Rewrite nginx domain name without adding www to add www.

Source: Internet
Author: User
: This article mainly introduces how to rewrite nginx domain names without adding www to add www. For more information about PHP tutorials, see.
Server {listen 80; server_name www.xxxx.net xxxx.net; # configure the publishing directory as/usr/local/nginx/data/rw-owsroot/usr/local/nginx/data/rw-ows; # add the following code error_page 405 = 405 $ 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 configuration ================ ========================== 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-, if-Modified-Since '; add_header 'content-length' 0; add_header 'content-type' 'text/plain charset = UTF-8'; # return 200; return 204 ;}} # submit a dynamic page 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 ;} # Configure Nginx dynamic/static separation. the defined static page is directly read from the Nginx release directory. Location ~. *\. (Html | gif | jpg | jpeg | bmp | png | ico | txt | js | css | swf) $ {root/usr/local/nginx/data/xxxx; # expires defines that the user's browser cache time is one day. if the static page is not updated frequently, you can set a longer period to save bandwidth and relieve the pressure on the server. 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 ($ ho St! = 'Www .xxxx.net ') {rewrite "^/(. *) $" http://www.xxxx.net/ $1 permanent ;}}

The above describes how to rewrite the nginx domain name without adding www to add www., including some content, hope to be helpful to friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.