Skip to content

Instantly share code, notes, and snippets.

@joepreludian
Created July 20, 2015 19:37
Show Gist options
  • Select an option

  • Save joepreludian/54180bdd0238b54f5f1b to your computer and use it in GitHub Desktop.

Select an option

Save joepreludian/54180bdd0238b54f5f1b to your computer and use it in GitHub Desktop.
NGINX Template to handle php throught PHP-FPM over /var/run/sock/php.sock
server {
listen 80;
server_name myawesomesite.com www.myawesomesite.com;
client_max_body_size 4G;
root /home/mysite/public_html;
access_log /home/mysite/logs/nginx-access.log;
error_log /home/mysite/logs/nginx-error.log;
index index.php;
location / {
try_files $uri $uri/ index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/sock/php.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 600;
include /etc/nginx/fastcgi_params;
}
}
@joepreludian
Copy link
Author

Will be needed to be used with PHP-FPM module. The scripts does the following:

  • Listen on port 80;
  • bind to myawesomesite.com and www.myawesomesite.com;
  • Will set a root;
  • At location "/" nginx will try to access file, if has any, if does not encounter, will try to load resource putting a bar on end of string. If it not have success, load index.php;
  • The magic happens on ~ .php. It means script will try to pass to php-fpm process any requests. If proxy fails raise an 404 error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment