我有“www.domain.com”并希望始终将其重写为“domain.com”(仅可通过/在端口 80 上使用)
我还想添加像'c.domain.com'这样的子域,总是重写(并且只可用)到' https://c.domain.com ',但我真的不知道如何在我有的时候进行另一个重写这适用于 WWW->NonWWW。
这是我的配置:
ssl_certificate /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
server {
listen 80;
server_name www.domain.com;
# redirect www to non-www
rewrite ^/(.*) http://domain.com/$1 permanent;
}
server {
listen 80;
server_name domain.com;
root /usr/share/nginx/$host;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args =404;
#try_files $uri $uri/;
}
# PHP-FPM
location ~* \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
server {
listen 443 default_server ssl;
server_name c.domain.com;
root /usr/share/nginx/$host;
index index.php index.html index.htm;
}
提前致谢!