Front-End Virtual server

Source: Internet
Author: User

server {//define virtual host Listen80; server_name www. xxx.com api.xxx.com; Access_log/srv/www/xxx.com/app/logs/www.xxx.com_access.Log; Error_log/srv/www/xxx.com/app/logs/www.xxx.com_error.Lognotice; Rewrite^/app\.php/? (. *) $/$1permanent; Rewrite the requested URL, where the function is to remove the app.php#rewrite ^/(. *)/$/$1 permanent;Root/srv/www/xxx.com/web; Error_page500 502 504/500.html; Location~* (/qrcode/(. *).png) $ {proxy_set_header X-real-ip$remote _addr; Proxy_set_header: Used to process the HTTP header to the server behind the proxy, X-real-ip x-forwarded-for is used to identify the original IP, $remote _addr: The user's IP address Proxy_set_hea Der X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; $http _host Destination Address Proxy_pass_header Set-cookies; Keep the HTTP header cookie Field Proxy_pass http://backend; } Location~ ^/admin/.*{proxy_set_header X-real-ip$remote _addr; Proxy_set_header X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; Proxy_pass_header Set-cookies; Auth_basic"Password"; Auth_basic_user_file/etc/nginx/htpasswd; Proxy_pass http://backend;} Location~ .*\. (js|css|gif|jpg|jpeg|png|bmp|swf|ico) $ {proxy_set_header X-real-ip$remote _addr; Proxy_set_header X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; Proxy_pass_header Set-cookies; Proxy_pass http://backend;} Location~* (/yyf-wheel (. *)) $ {Proxy_set_header X-real-ip$remote _addr; Proxy_set_header X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; Proxy_pass_header Set-cookies; Proxy_pass http://lol;} Location~* (/index (. *) |/get/user|/product/(. *) |/usr/(. *))) $ {Proxy_set_header X-real-ip$remote _addr; Proxy_set_header X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; Proxy_pass_header Set-cookies; Proxy_pass http://users;} Location~* (/invite/(. *) |/media/(. *) |/lib/responsive_filemanager/(. *))) $ {Proxy_set_header X-real-ip$remote _addr; Proxy_set_header X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; Proxy_pass_header Set-cookies; Proxy_pass http://backend;} Location/{proxy_set_header X-real-ip$remote _addr; Proxy_set_header X-forwarded- for $remote _addr; Proxy_set_header Host$http _host; Proxy_pass_header Set-cookies; Proxy_pass http://Dota2;    }}
    1. Location matching rules
      • An = exact match is already prefaced
        If only the request at the end of the root directory is matched in A, no strings can be followed.
      • ^~Begins with a URI that begins with a regular string, not a regular match
      • ~ Starts with a case-sensitive regular match;
      • ~* start indicates a case-insensitive regular match
      • /generic match, if there is no other match, any request will match to

Sequential no priority:
(location =) > (location full path) > (location ^~ path) > (Location ~,~* regular order) > (Location section start path) > (/)

The above matching results
According to the location above, the following sample matches are set up:

      • /config A
        exactly matches exactly, even if/index.html does not match
      • /downloads/download.html config b
        Match b , there is no match, b
      • /images/1.gif, configuration D
        matches to F, match down to D, stop down
      • /images/abc/def, config D
        Longest match to G, down to D, stop down
        you can see that any/images/beginning with a match to D and stop, FG write here is meaningless, H is never round, here just to illustrate the match order
      • /documents/ document.html, config C
        matches to C, there are no matches down, C
      • /documents/1.jpg, configuration E
        matches to C, the regular match to E
      • /documents/abc.jpg config CC
        longest match to C, down regular order to CC, not down to e
Therefore, in actual use, the individual feel that there are at least three matching rule definitions, as follows: #直接匹配网站根, through the domain name to visit the site home more frequently, using this will speed up processing, the official website said. #这里是直接转发给后端应用服务器了, can also be a static home # first required rule location =/{    Proxy_pass http://tomcat:8080/index}# the second required rule is to handle a static file request, This is nginx as the strength of the HTTP server # There are two configuration modes, directory matching or suffix matching, either one or use location ^~/static/{    root/webroot/static/;} Location ~* \. (Gif|jpg|jpeg|png|css|js|ico) $ {    root/webroot/res/;} #第三个规则就是通用规则, used to forward a dynamic request to the backend Application Server # non-static file request is the default is dynamic request, own according to the actual grasp # after all, some of the current framework of popular, with the. php,.jsp suffix is rare. Location/{    Proxy_ Pass http://tomcat:8080/}

  

Front-End Virtual server

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.