Created
January 24, 2013 13:59
-
-
Save melchoy/4621918 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| http { | |
| # Declare index at http level | |
| index index.html index.php; | |
| server { | |
| # Set IP & Port For Server Block | |
| listen 00.000.000.000:80; | |
| # Set Server Name | |
| server_name www.example.com; | |
| # Redirect WWW to non WWW (http://wiki.nginx.org/Pitfalls) | |
| return 301 $scheme://example.com$request_uri; | |
| } | |
| server { | |
| # Set IP & Port For Server Block | |
| listen 00.000.000.000:80 default_server; | |
| # Set Server Name | |
| server_name example.com; | |
| # Set Path To Public Folder | |
| root /srv/www/example.com/pub; | |
| # Set Default File (http://wiki.nginx.org/HttpIndexModule) - index.html before index.php for ExpressionEngine's offline.html | |
| index index.html index.php; | |
| access_log /srv/www/example.com/log/access.log; | |
| error_log /srv/www/example.com/log/error.log; | |
| # (http://wiki.nginx.org/IfIsEvil) | |
| location / { | |
| try_files $uri $uri/ @ee; | |
| } | |
| # Needed For Most PHP Frameworks | |
| location @ee { | |
| rewrite ^(.*) /index.php$1 last; | |
| } | |
| # Use of 404 set in ExpressionEngine | |
| error_page 404 /site/404; | |
| # Set File Type For Mapping Prefix | |
| location ~ \.(?:ico|asf|asx|wax|wmv|wmx|avi|bmp|class|css|divx|doc|docx|exe|eot|gif|gz|gzip|htc|ico|jpe?g|js|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|otf|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|ttf|ttc|wav|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)$ { | |
| expires 31536000s; | |
| # Let's Make Sure Firefox Uses Our Web Fonts. You can also set specific domains e.g. static.mycdn.com, etc. | |
| add_header "Access-Control-Allow-Origin" "*"; | |
| add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate"; | |
| } | |
| location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ { | |
| expires 3600s; | |
| add_header Pragma "public"; | |
| add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate"; | |
| } | |
| location = /robots.txt { access_log off; log_not_found off; } | |
| location = /favicon.ico { access_log off; log_not_found off; } | |
| location ~ /\. { access_log off; log_not_found off; deny all; } | |
| # Lets Pass All PHP Files To PHP-FPM/PHP-FCGI // Settings defer based on PHP implementation e.g. PHP-FPM use etc. | |
| location ~ \.php$ { | |
| # Zero-day exploit defense (https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/) | |
| try_files $uri =404; | |
| fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
| # Lets Opt For Unix Socket (http://wiki.nginx.org/PHPFcgiExample) | |
| fastcgi_pass unix:/var/run/php5-fpm.sock; | |
| fastcgi_index index.php; | |
| include fastcgi_params; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment