nginx 域名301重定向 rewrite跳转 无www跳转到有www
程序员文章站
2022-06-16 21:49:14
...
server {
listen 80;
server_name www.xxx.com xxx.com;
if ($host = xxx.com ) {
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
}
error_page 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
listen 80;
server_name www.xxx.com xxx.com;
if ($host = xxx.com ) {
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
}
error_page 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:8080;
}
}
以上就介绍了nginx 域名301重定向 rewrite跳转 无www跳转到有www,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
下一篇: CentOS7 编译安装LNMP