Skip to content

Instantly share code, notes, and snippets.

@danieladarve
Last active March 25, 2021 22:04
Show Gist options
  • Save danieladarve/d733bde89988bfba918ff5b3bf4862d9 to your computer and use it in GitHub Desktop.
Save danieladarve/d733bde89988bfba918ff5b3bf4862d9 to your computer and use it in GitHub Desktop.
nginx-server-template
server {
listen 127.0.0.1:80;
listen [::]:443 ssl http2;
server_name <your_website>.test www.<your_website>.test *.<your_website>.test;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name <your_website>.test www.<your_website>.test *.<your_website>.test;
root /; # path to your app
index index.php index.html index.htm;
charset utf-8;
client_max_body_size 512M;
http2_push_preload on;
location / {
internal;
alias /;
# CORS Rules #
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS, DELETE';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization';
# END of CORS Rules #
try_files $uri $uri/ /index.php?$query_string;
}
ssl_certificate "/opt/homebrew/etc/nginx/ssl/<your_website>.crt";
ssl_certificate_key "/opt/homebrew/etc/nginx/ssl/<your_website>.key";
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/opt/homebrew/var/log/nginx/<your_website>-error.log";
error_page 404 /index.php;
location ~ [^/]\.php(/|$) {
# CORS Rules
add_header Access-Control-Allow-Origin *;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, OPTIONS, DELETE';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization';
# END of CORS Rules #
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9074; #PORTS:> PHP@7.0 9000 PHP@7.1 9001 PHP@7.2 9002 PHP@8.1 9004
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~ /\.ht {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment