Last active
September 28, 2020 12:49
-
-
Save thephucit/268071a21e57b42acd29d80f857ac30c to your computer and use it in GitHub Desktop.
Octobercms NginX
This file contains hidden or 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
server { | |
listen 80; | |
server_name .example.co.uk.dev; | |
access_log /usr/local/var/log/nginx/example.co.uk-access.log; | |
error_log /usr/local/var/log/nginx/example.co.uk-error.log error; | |
root /var/www/example.co.uk/public; | |
index index.php index.html; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~ \.php { | |
fastcgi_index index.php; | |
fastcgi_pass unix:/usr/local/var/run/php-fpm.socket; | |
include fastcgi_params; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_param PATH_INFO $fastcgi_path_info; | |
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
# Prevents caching of css/less/js/images, only use this in development | |
location ~* \.(css|less|js|jpg|png|gif)$ { | |
add_header Cache-Control "no-cache, no-store, must-revalidate"; | |
add_header Pragma "no-cache"; | |
expires 0; | |
} | |
} |
This file contains hidden or 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
## SOCKET | |
upstream side_sock { | |
server 127.0.0.1:3000; | |
keepalive 32; | |
} | |
# SSL | |
server { | |
listen 80; | |
listen 443 ssl http2; | |
server_name domain.com; | |
ssl_certificate fullchain.pem; # managed by Certbot | |
ssl_certificate_key privkey.pem; # managed by Certbot | |
location / { | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
client_max_body_size 50M; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Frame-Options SAMEORIGIN; | |
proxy_buffers 256 16k; | |
proxy_buffer_size 16k; | |
client_body_timeout 60; | |
send_timeout 300; | |
lingering_timeout 5; | |
proxy_connect_timeout 90; | |
proxy_send_timeout 300; | |
proxy_read_timeout 90s; | |
proxy_pass http://side_sock; | |
} | |
} |
This file contains hidden or 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
server { | |
listen 80; | |
#listen [::]:80; | |
listen 443 ssl http2; | |
server_name domain.com www.domain.com; | |
ssl_certificate fullchain.pem; | |
ssl_certificate_key privkey.pem; | |
root /usr/share/nginx/html/project; | |
index index.html index.htm index.php; | |
charset utf-8; | |
if (!-d $request_filename) { | |
rewrite ^/(.+)/$ /$1 permanent; | |
} | |
location / { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
# | |
# Custom headers and headers various browsers *should* be OK with but aren't | |
# | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Lang,Token'; | |
# | |
# Tell client that this pre-flight info is valid for 20 days | |
# | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Content-Type' 'text/plain; charset=utf-8'; | |
add_header 'Content-Length' 0; | |
return 204; | |
} | |
if ($request_method ~* "(GET|POST)") { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Lang,Token'; | |
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; | |
} | |
# Let OctoberCMS handle everything by default. | |
# The path not resolved by OctoberCMS router will return OctoberCMS's 404 page. | |
# Everything that does not match with the whitelist below will fall into this. | |
rewrite ^/.*$ /index.php last; | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
# Pass the PHP scripts to FastCGI server | |
location ~ ^/index.php { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
# | |
# Custom headers and headers various browsers *should* be OK with but aren't | |
# | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Lang,Token'; | |
# | |
# Tell client that this pre-flight info is valid for 20 days | |
# | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Content-Type' 'text/plain; charset=utf-8'; | |
add_header 'Content-Length' 0; | |
return 204; | |
} | |
if ($request_method ~* "(GET|POST)") { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Lang,Token'; | |
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; | |
} | |
# Write your FPM configuration here | |
fastcgi_pass php-fpm; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# Whitelist | |
## Let October handle if static file not exists | |
location ~ ^/favicon\.ico { try_files $uri /index.php; } | |
location ~ ^/sitemap\.xml { try_files $uri /index.php; } | |
location ~ ^/robots\.txt { try_files $uri /index.php; } | |
location ~ ^/humans\.txt { try_files $uri /index.php; } | |
## Let nginx return 404 if static file not exists | |
location ~ ^/storage/app/uploads/public { try_files $uri 404; } | |
location ~ ^/storage/app/uploads/user_.*/ { try_files $uri 404; } | |
location ~ ^/storage/app/media { try_files $uri 404; } | |
location ~ ^/storage/temp/public { try_files $uri 404; } | |
location ~ ^/modules/.*/assets { try_files $uri 404; } | |
location ~ ^/modules/.*/resources { try_files $uri 404; } | |
location ~ ^/modules/.*/behaviors/.*/assets { try_files $uri 404; } | |
location ~ ^/modules/.*/behaviors/.*/resources { try_files $uri 404; } | |
location ~ ^/modules/.*/widgets/.*/assets { try_files $uri 404; } | |
location ~ ^/modules/.*/widgets/.*/resources { try_files $uri 404; } | |
location ~ ^/modules/.*/formwidgets/.*/assets { try_files $uri 404; } | |
location ~ ^/modules/.*/formwidgets/.*/resources { try_files $uri 404; } | |
location ~ ^/modules/.*/reportwidgets/.*/assets { try_files $uri 404; } | |
location ~ ^/modules/.*/reportwidgets/.*/resources { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/assets { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/resources { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/behaviors/.*/assets { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/behaviors/.*/resources { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/reportwidgets/.*/assets { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/reportwidgets/.*/resources { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/formwidgets/.*/assets { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/formwidgets/.*/resources { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/widgets/.*/assets { try_files $uri 404; } | |
location ~ ^/plugins/.*/.*/widgets/.*/resources { try_files $uri 404; } | |
location ~ ^/themes/.*/assets { try_files $uri 404; } | |
location ~ ^/themes/.*/resources { try_files $uri 404; } | |
location ~ ^/themes/.*/partials { try_files $uri 404; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment