我有www.domain.com'并希望始终将其重写为' domain.com' (仅适用于/通过端口80)
我还想添加类似' c.domain.com'这样的子域名,总是重新编辑(并且仅适用于)https://c.domain.com',但我不会&#39我真的知道如何在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;
}
提前致谢!
答案 0 :(得分:1)
server {
listen 80;
server_name www.domain.com;
return 301 http://domain.com$request_uri;
}
server {
listen 80;
server_name domain.com;
[...]
}
server {
listen 80;
server_name c.domain.com;
return 301 https://c.domain.com$request_uri;
}
server {
listen 443 default_server ssl;
server_name c.domain.com;
[...]
}
文档: