本文主要是介绍nginx实现顶级域名、二级域名被配置相同,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
存在这样的需求,www.kunming-marathon.com kunming-marathon.com 两个域名指向同一个赛事的网址,需要将一个域名做一下跳转,一般是顶级域名转一下rewrite,
server{listen 80;server_name kunming-marathon.com;rewrite ^/(.*) http://www.kunming-marathon.com/$1 permanent;
}
完整的配置代码:
#www.kunming-marathon.com kunming-marathon.comserver{listen 80;server_name kunming-marathon.com;rewrite ^/(.*) http://www.kunming-marathon.com/$1 permanent;
}server {listen 80;server_name www.kunming-marathon.com;#charset koi8-r;#access_log logs/host.access.log main;location / {proxy_next_upstream error timeout http_500 http_502 http_504;proxy_read_timeout 60s;proxy_set_header Host $host;proxy_pass http://RUN24HOURS;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_intercept_errors on;client_max_body_size 15M;index index.html index.htm;rewrite ^/$ http://www.kunming-marathon.com/11577 break;}location ^~ /errorpage {root /home/nginx/nginx_data;}error_page 500 502 503 504 /errorpage/500.html;error_page 400 404 /errorpage/404.html;}
这篇关于nginx实现顶级域名、二级域名被配置相同的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!