Created
January 2, 2020 02:51
-
-
Save patrickcurl/668dec681060d935eaee29b5fdfe0a52 to your computer and use it in GitHub Desktop.
Catchall Nginx config for PHP
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
server { | |
listen 80; | |
listen [::]:80; | |
server_name ~^(?<domain>.+)\.test$; | |
root /home/<yourusername>/sites/$domain; | |
index index.php index.html index.htm; | |
# serve static files directly | |
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { | |
access_log off; | |
expires max; | |
} | |
# catch all | |
error_page 404 /index.php; | |
error_log /var/log/nginx/error.log; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
# A bunch of perm page redirects from my old | |
# site structure for SEO purposes. Not interesting. | |
# include /etc/nginx/templates/redirects; | |
} | |
if (!-d $request_filename) { | |
rewrite ^/(.+)/$ /$1 permanent; | |
} | |
location ~* \.php$ { | |
try_files $uri /index.php =404; | |
# Server PHP config. | |
# Change THIS IF your sock is in a different location. | |
fastcgi_pass unix:/run/php-fpm/php-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
# Typical vars in here, nothing interesting. | |
include /etc/nginx/fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
location ~ /\.ht { | |
# Hells no, we usin nginx up in this mutha. (deny .htaccess) | |
deny all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment