您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

nginx域名重写 不加www 转到加www.

2024/4/30 9:35:30发布24次查看
server { listen 80; server_name www.xxxx.net xxxx.net; #配置发布目录为/usr/local/nginx/data/rw-ows root /usr/local/nginx/data/rw-ows; #添加以下405代码 error_page 405 =200 $uri; location / { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://rw-ows; #=========================cors nginx配置============================= if ($http_origin ~* (https?://[^/]*\.roamwifi\.net(:[0-9]+)?)$) { set $cors true; } if ($request_method = 'options') { set $cors ${cors}options; } if ($request_method = 'get') { set $cors ${cors}get; } if ($request_method = 'post') { set $cors ${cors}post; } if ($cors = trueget) { add_header 'access-control-allow-origin' $http_origin; add_header 'access-control-allow-credentials' 'true'; } if ($cors = truepost) { add_header 'access-control-allow-origin' $http_origin; add_header 'access-control-allow-credentials' 'true'; } if ($cors = trueoptions) { #add_header 'access-control-allow-origin' $http_origin; add_header 'access-control-allow-origin' '*'; add_header 'access-control-allow-credentials' 'true'; add_header 'access-control-max-age' 1728000; add_header 'access-control-allow-headers' 'authorization,content-type,accept,origin,user-agent,dnt,cache-control,x-mx-reqtoken,keep-alive,x-requested-with,if-modified-since'; add_header 'content-length' 0; add_header 'content-type' 'text/plain charset=utf-8'; #return 200; return 204; } } #动态页面交给http://rw-ows, location ~ .*\.(jsp|do)?$ { proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_pass http://rw-ows; } #配置nginx动静分离,定义的静态页面直接从nginx发布目录读取。 location ~ .*\.(html|gif|jpg|jpeg|bmp|png|ico|txt|js|css|swf)$ { root /usr/local/nginx/data/xxxx; #expires定义用户浏览器缓存的时间为1天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力 expires 1d; } location = /anon_login.jsp { return 301 https://$server_name$request_uri; } location = /anon_register.jsp { return 301 https://$server_name$request_uri; } location = /anon_forgetpwd.jsp { return 301 https://$server_name$request_uri; } if ( $host != 'www.xxxx.net' ) { rewrite ^/(.*)$ http://www.xxxx.net/$1 permanent; } }
以上就介绍了nginx域名重写 不加www 转到加www.,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product