Last active
December 16, 2015 21:49
-
-
Save kvz/5502293 to your computer and use it in GitHub Desktop.
First swing at public cake 2.0 nginx vhost. please improve
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
# Be sure to checkout the official docs for a smaller example | |
# http://book.cakephp.org/2.0/en/installation/url-rewriting.html#pretty-urls-on-nginx | |
http { | |
# With this trick, you can pass per-environment variables and | |
# PHP settings to FastCGI depending on the host header value. | |
map $http_host $environment { | |
example.local development; | |
example.com production; | |
} | |
# Forward 80 -> 443 | |
#server { | |
# listen 80; | |
# server_name secure.example.com; | |
# rewrite ^(.+)$ https://${http_host}$1 permanent; | |
# break; | |
#} | |
# Forward www.example.com -> example.com | |
#server { | |
# listen 80; | |
# server_name www.example.com; | |
# rewrite ^(.+)$ https://example.com$1 permanent; | |
# break; | |
#} | |
server { | |
listen 80; | |
server_name example.com; | |
root /var/www/example.com/webroot; | |
index index.php; | |
access_log /var/log/nginx/example.com-access.log; | |
error_log /var/log/nginx/example.com-error.log; | |
location / { | |
try_files $uri $uri/ /index.php?$uri&$args; | |
} | |
# Static files: no logging & caching at client-side | |
location ~ ^/(css/|js/|img/|favicon\.ico) { | |
access_log off; | |
expires 7d; | |
add_header Cache-Control public; | |
} | |
# Deny access to all hidden files | |
location ~ /\. { | |
deny all; | |
} | |
# regex may need improvements as this could | |
# possibly feed | |
location ~ \.php$ { | |
# For security, add the following try_files, or cgi.fix_pathinfo=0 to php.ini | |
# otherwise /uploads/file.jpg/wtf_i_will_run_in.php could be fed to this location, | |
# php turns it into /uploads/file.jpg. Then if that contained code to email your database | |
# passwords, you have a problem. | |
try_files $uri =404; | |
# FastCGI proxy | |
fastcgi_pass unix:/var/run/php5-fpm.sock; # -or- # fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_intercept_errors on; | |
# It's not possible to use if statements here, so we use maps (see top of file) | |
# To set variables depending on host header value. | |
fastcgi_param ENVIRONMENT $environment; | |
# You could also temper with php settings based on environment: | |
# fastcgi_param PHP_VALUE "xyz=$xyz"; | |
include fastcgi_params; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment