Skip to content

Instantly share code, notes, and snippets.

@hrvoj3e
Forked from sgomez84/nginx.conf
Created August 19, 2020 06:23
Show Gist options
  • Save hrvoj3e/6dae73e2c34d0e26dc2986e693837ff1 to your computer and use it in GitHub Desktop.
Save hrvoj3e/6dae73e2c34d0e26dc2986e693837ff1 to your computer and use it in GitHub Desktop.
Nginx Proxy Pass to PHP-FPM
upstream phpfpm {
#server unix:/var/run/php5-fpm.sock;
#avoid sockets for nginx-fpm on Linux, they are good for BSD
server 127.0.0.1:9000;
}
server {
listen 8080;
server_name sumhr.com;
rewrite ^(.*) $scheme://www.sumhr.com$1 permanent;
}
server {
listen 8080;
charset utf-8;
server_name www.sumhr.com;
root /var/www/sumhr_wp;
index index.php index.html index.htm;
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
access_log /var/www/sumhrapp/logs/access.log;
error_log /var/www/sumhrapp/logs/error.log warn;
# Global restrictions configuration file.
# Designed to be included in any server {} block.</p>
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
deny all;
}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
location ~ \.php$ {
try_files $uri =404;
# Fix for server variables that behave differently under nginx/php-fpm than typically expected
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Include the standard fastcgi_params file included with nginx
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
# Override the SCRIPT_FILENAME variable set by fastcgi_params
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Pass to upstream PHP-FPM; This must match whatever you name your upstream connection
fastcgi_pass phpfpm;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment