Created
January 4, 2013 10:54
-
-
Save lgoldstien/4451641 to your computer and use it in GitHub Desktop.
Nginx configuration with SSL and a few url rewrites
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 | |
server { | |
listen 80; | |
listen [IPv6]:80 default ipv6only=on; | |
server_name site www.site; | |
access_log /var/www/site/logs/nginx.access.log; | |
error_log /var/www/site/logs/nginx.error.log; | |
root /var/www/site/www; | |
index index.php index.htm index.html; | |
location ~ .php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/site/www$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# Backoffice locations | |
location /app/backoffice { | |
rewrite ^ https://$server_name$request_uri? permanent; | |
} | |
location /blog/ { | |
try_files $uri $uri/ /blog/index.php?q=$uri&$args; | |
} | |
rewrite ^/announcements$ /./announcements.php last; | |
rewrite ^/downloads$ /./downloads.php last; | |
rewrite ^/knowledgebase$ /./knowledgebase.php last; | |
rewrite ^/knowledgebase/([0-9]+)/[a-zA-Z0-9_-]+.html$ /./knowledgebase.php?action=displayarticle&id=$1 last; | |
rewrite ^/knowledgebase/([0-9]+)/([^/]*)$ /./knowledgebase.php?action=displaycat&catid=$1 last; | |
rewrite ^/announcements/([0-9]+)/[a-zA-Z0-9_-]+.html$ /./announcements.php?id=$1 last; | |
rewrite ^/downloads/([0-9]+)/([^/]*)$ /./downloads.php?action=displaycat&catid=$1 last; | |
} | |
# HTTPS | |
server { | |
listen 80; | |
listen [IPv6]:80 default ipv6only=on; | |
server_name site www.site; | |
ssl on; | |
ssl_certificate /var/www/ipgeek.co.uk/certs/ssl.crt; | |
ssl_certificate_key /var/www/ipgeek.co.uk/certs/ssl.key; | |
ssl_session_timeout 5m; | |
ssl_prefer_server_ciphers on; | |
access_log /var/www/site/logs/nginx.access.log; | |
error_log /var/www/site/logs/nginx.error.log; | |
root /var/www/site/www; | |
index index.php index.htm index.html; | |
location ~ .php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/site/www$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# Backoffice locations | |
location /app/backoffice { | |
auth_basic "Restricted Access"; | |
auth_basic_user_file /var/www/site/auth/backoffice; | |
try_files $uri $uri/ /index.php; | |
} | |
location /blog/ { | |
try_files $uri $uri/ /blog/index.php?q=$uri&$args; | |
} | |
rewrite ^/announcements$ /./announcements.php last; | |
rewrite ^/downloads$ /./downloads.php last; | |
rewrite ^/knowledgebase$ /./knowledgebase.php last; | |
rewrite ^/knowledgebase/([0-9]+)/[a-zA-Z0-9_-]+.html$ /./knowledgebase.php?action=displayarticle&id=$1 last; | |
rewrite ^/knowledgebase/([0-9]+)/([^/]*)$ /./knowledgebase.php?action=displaycat&catid=$1 last; | |
rewrite ^/announcements/([0-9]+)/[a-zA-Z0-9_-]+.html$ /./announcements.php?id=$1 last; | |
rewrite ^/downloads/([0-9]+)/([^/]*)$ /./downloads.php?action=displaycat&catid=$1 last; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment