Last active
January 4, 2016 09:28
-
-
Save chaosmail/8601830 to your computer and use it in GitHub Desktop.
nginx-localhost-configuration
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 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
server_name .my_site.dev; | |
root /var/www/my_site/public; | |
# It's always good to set logs, note however you cannot turn off the error log | |
# setting error_log off; will simply create a file called 'off'. | |
access_log /var/log/nginx/my_site.access.log; | |
error_log /var/log/nginx/my_site.error.log debug; | |
index index.html index.htm index.php; | |
# Check if file exists | |
if (!-e $request_filename) | |
{ | |
rewrite ^/(.*)$ /index.php?/$1 last; | |
break; | |
} | |
# The PHP Inclusion Block | |
location ~ \..*/.*\.php$ | |
{ | |
return 403; | |
} | |
# This block will catch static file requests, such as images, css, js | |
# The ?: prefix is a 'non-capturing' mark, meaning we do not require | |
# the pattern to be captured into $1 which should help improve performance | |
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { | |
# Some basic cache-control for static files to be sent to the browser | |
expires max; | |
add_header Pragma public; | |
add_header Cache-Control "public, must-revalidate, proxy-revalidate"; | |
} | |
# this prevents hidden files (beginning with a period) from being served | |
location ~ /\. { | |
access_log off; | |
log_not_found off; | |
deny all; | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
location ~ \.php { | |
# for security reasons the next line is highly encouraged | |
try_files $uri =404; | |
fastcgi_param QUERY_STRING $query_string; | |
fastcgi_param REQUEST_METHOD $request_method; | |
fastcgi_param CONTENT_TYPE $content_type; | |
fastcgi_param CONTENT_LENGTH $content_length; | |
fastcgi_param SCRIPT_NAME $fastcgi_script_name; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_param REQUEST_URI $request_uri; | |
fastcgi_param DOCUMENT_URI $document_uri; | |
fastcgi_param DOCUMENT_ROOT $document_root; | |
fastcgi_param SERVER_PROTOCOL $server_protocol; | |
fastcgi_param GATEWAY_INTERFACE CGI/1.1; | |
fastcgi_param SERVER_SOFTWARE nginx; | |
fastcgi_param REMOTE_ADDR $remote_addr; | |
fastcgi_param REMOTE_PORT $remote_port; | |
fastcgi_param SERVER_ADDR $server_addr; | |
fastcgi_param SERVER_PORT $server_port; | |
fastcgi_param SERVER_NAME $server_name; | |
# If using a TCP connection... | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_intercept_errors on; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment