Last active
December 14, 2015 19:28
-
-
Save tim-peterson/5136554 to your computer and use it in GitHub Desktop.
nginx.conf to rewrite of example.com/sites/medicine to medicine.example.com
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
user www-data; | |
worker_processes 4; | |
pid /var/run/nginx.pid; | |
events { | |
# worker_connections 768; | |
worker_connections 7680; | |
# multi_accept on; | |
} | |
error_log /var/log/nginx/error.log; | |
http{ | |
## | |
# Basic Settings | |
## | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 2048; | |
# server_tokens off; | |
# server_names_hash_bucket_size 64; | |
# server_name_in_redirect off; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
## | |
# Logging Settings | |
## | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
## | |
# Virtual Host Configs | |
## | |
include /etc/nginx/conf.d/*.conf; | |
include /etc/nginx/sites-enabled/*; | |
#server { | |
# listen 80; | |
# listen 443 ssl spdy; | |
# server_name medicine.example.com; | |
# return 301 https://example.com/sites/medicine$request_uri; | |
#} | |
# location / { | |
# resolver 8.8.8.8; | |
# rewrite ^([^.]*[^/])$ $1/ permanent; | |
# proxy_pass_header Set-Cookie; | |
# proxy_pass https://example.com/sites/physics$request_uri; | |
# } | |
#} | |
#server { | |
# server_name user.cooking.com; | |
# include sites-available/server.conf; | |
# fastcgi_param SCRIPT_FILENAME $document_root/index.php/user/$args; | |
# include sites-available/php.conf; | |
#} | |
server { | |
# listen 80; | |
listen 443 ssl spdy; | |
ssl on; | |
ssl_certificate xxxxxxx.xxx; | |
ssl_certificate_key xxxxxxxx.xxx; | |
# server_name example.com; | |
server_name example.com physics.example.com medicine.example.com; | |
root /var/www; | |
# index index.html index.php index.htm; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
if ($host = "physics.example.com") { | |
rewrite . /sites/physics$request_uri; | |
} | |
# if ($host ~* ^www\.([a-z0-9]*)\.(example\.com) ) | |
# { | |
# set $storename $1; | |
# set $host_without_www $2; | |
# rewrite ^/(.*)$ $scheme://$storename.$host_without_www/ permanent; | |
# } | |
# if ($host ~* ^([a-z0-9]+)\.(example\.com)) | |
# { | |
# set $storename $1; | |
# set $host_without_www $2; | |
# rewrite ^/$ /index.php/tags/index/ last; | |
# rewrite ^/(.+)$ /index.php/$1 last; | |
# } | |
# canonicalize codeigniter url end points | |
# if your default controller is something other than "welcome" you should change the following | |
# if ($request_uri ~* ^(/mall(/index)?|/index(.php)?)/?$){ | |
# rewrite ^(.*)$ / permanent; | |
# rewrite ^/(.*) http://example.info/$1 permanent; | |
# } | |
# removes trailing "index" from all controllers | |
if ($request_uri ~* index/?$){ | |
rewrite ^/(.*)/index/?$ /$1 permanent; | |
} | |
# removes trailing slashes (prevents SEO duplicate content issues) | |
if (!-d $request_filename){ | |
rewrite ^/(.+)/$ /$1 permanent; | |
} | |
# removes access to "system" folder, also allows a "System.php" controller | |
if ($request_uri ~* ^/system){ | |
rewrite ^/(.*)$ /index.php?/$1 last; | |
break; | |
} | |
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap | |
if (!-e $request_filename){ | |
rewrite ^/(.*)$ /index.php?/$1 last; | |
break; | |
} | |
# catch all | |
error_page 404 /index.php; | |
location / { | |
#try_files $uri $uri/ /index.php; | |
index index.php index.html; | |
} | |
# use fastcgi for all php files | |
location ~ \.php$ | |
{ | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; | |
include /etc/nginx/fastcgi_params; | |
} | |
# deny access to apache .htaccess files | |
location ~ /\.ht { | |
deny all; | |
} | |
} #end server | |
proxy_buffer_size 128k; | |
proxy_buffers 4 256k; | |
proxy_busy_buffers_size 256k; | |
fastcgi_buffers 16 16k; | |
fastcgi_buffer_size 32k; | |
} #end http | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment