Created
February 7, 2013 19:05
-
-
Save thomasgriffin/4733283 to your computer and use it in GitHub Desktop.
Map subdomains to URLs in nginx with WordPress.
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
server { | |
listen 80; | |
listen 443 ssl; | |
server_name ~^(?<user>[a-zA-Z0-9-]+)\.example\.com$; | |
location / { | |
resolver 8.8.8.8; | |
rewrite ^([^.]*[^/])$ $1/ permanent; | |
proxy_pass_header Set-Cookie; | |
proxy_pass $scheme://example.com/user/$user$request_uri; | |
} | |
} | |
server { | |
listen 80; | |
listen 443 ssl; | |
server_name www.example.com; | |
return 301 $scheme://example.com$request_uri; | |
} | |
server { | |
listen 80; | |
server_name example.com; | |
access_log /var/www/example.com/logs/access.log; | |
error_log /var/www/example.com/logs/error.log; | |
root /var/www/example.com/public; | |
index index.php; | |
location / { | |
try_files $uri $uri/ @wordpress /index.php?q=$request_uri; | |
} | |
location @wordpress { | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include /etc/nginx/fastcgi_params; | |
fastcgi_param SCRIPT_NAME /index.php; | |
} | |
# Pass the PHP scripts to FastCGI server listening on UNIX sockets. | |
# | |
location ~ \.php$ { | |
try_files $uri @wordpress; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} | |
server { | |
listen 443 ssl; | |
ssl on; | |
keepalive_timeout 70; | |
server_name example.com; | |
ssl_certificate ssl/example.com.chained.crt; | |
ssl_certificate_key ssl/example.key; | |
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; | |
ssl_ciphers HIGH:!aNULL:!MD5; | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_timeout 10m; | |
ssl_prefer_server_ciphers on; | |
root /var/www/example.com/public; | |
index index.php; | |
location / { | |
try_files $uri $uri/ @wordpress /index.php?q=$request_uri; | |
} | |
location @wordpress { | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include /etc/nginx/fastcgi_params; | |
fastcgi_param SCRIPT_NAME /index.php; | |
} | |
# Pass the PHP scripts to FastCGI server listening on UNIX sockets. | |
# | |
location ~ \.php$ { | |
try_files $uri @wordpress; | |
fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
I read your post and it is what I wish. I want Permalink :
http://my-domain.com/%postname%/ will be http://%postname%.my-domain.com
My server is Centos 5, use port 80 for nginx + post 8080 for apache as proxy.
Domain ready setup WildCard DNS
This is my config for /etc/httpd/conf/httpd.conf:
NameVirtualHost *:8080
<VirtualHost *:8080>
ServerAdmin [email protected]
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domains/domain.com
ErrorLog logs/domain.com-error_log
CustomLog logs/domain.com-access_log common
And this is /etc/nginx/conf.d/domain.com.conf
server {
listen 80;
server_name domain.com www.domain.com;
access_log /var/log/nginx/domain.com.access.log ;
error_log /var/log/nginx/domain.com.error.log ;
location ~ .(js|css|jpg|jpeg|gif|png|ico|flv|mp3|mpg|mpeg|zip|tgz|rar|bz2|doc|xls|exe|pdf|ppt|tar|mid|midi|wav|bmp|rtf)$ {
root /var/www/domains/domain.com;
}
location / {
proxy_pass http://111.111.111.111:8080/ ;
include /etc/nginx/conf.d/proxy.conf;
}
}
How to do in this case.
Please help
Thanks