Created
December 2, 2018 16:02
-
-
Save kevinluo201/476befb589445ccd5b920199b667dca0 to your computer and use it in GitHub Desktop.
nginx.conf with passenger and php fastcgi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
passenger_root /home/apps/.rvm/gems/ruby-2.3.7/gems/passenger-5.3.7; | |
passenger_ruby /home/apps/.rvm/gems/ruby-2.3.7/wrappers/ruby; | |
include mime.types; | |
default_type application/octet-stream; | |
sendfile on; | |
keepalive_timeout 65; | |
# nginx 預設的 server,留著可以在 server 啟動後,用瀏覽器去確定有成功 | |
server { | |
listen 80; | |
server_name localhost; | |
location / { | |
root html; | |
index index.html index.htm; | |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} | |
# another virtual host using mix of IP-, name-, and port-based configuration | |
# | |
# Upstream to abstract backend connection(s) for php | |
# 宣告 php 的 fastcgi 的接口,這樣讓 nginx 知道怎麼處理 *.php 檔案 | |
upstream php { | |
server unix:/var/run/php/php7.2-fpm.sock; | |
} | |
# 設定一個 Wordpress server | |
server { | |
listen 80; | |
listen 443 ssl; | |
root /path/to/website/folder; # 可以是 /var/www/tw.yahoo.com 之類的,把資料夾設成網址名 | |
server_name some.url.for.wordpress; | |
ssl_certificate /some_path/certificate.crt; | |
ssl_certificate_key /some_path/private.key; | |
index index.php; | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location / { | |
# This is cool because no php is touched for static content. | |
# include the "?$args" part so non-default permalinks doesn't break when using query string | |
try_files $uri $uri/ /index.php?$args; | |
} | |
location ~ \.php$ { | |
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini | |
include fastcgi.conf; | |
fastcgi_intercept_errors on; | |
fastcgi_pass php; # 這裡是關鍵,把 php 的檔案丟到上面設定 php upstream | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { | |
expires max; | |
log_not_found off; | |
} | |
} | |
server { | |
listen 80; | |
listen 443 ssl; | |
server_name some.rails.site; | |
root /home/apps/some_rails_site/public; | |
passenger_enabled on; | |
client_max_body_size 1G; | |
ssl_certificate /rails_ssl/certificate.crt; | |
ssl_certificate_key /rails_ssl/private.key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment