search

Home  >  Q&A  >  body text

nginx+nodejs

The first location below is to transfer http://localhost:1337/gek/ to node for processing.
What is the second location below? Is it to process the interface passed from the backend?
do not understand!!!

server {
   listen   80;
   server_name gek.show.com;

   location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass   http://localhost:1337/gek/;
    }

    location ~ ^/okc/rest{
        proxy_store off;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_set_header Host "gek.show.com"; 
        #proxy_pass http://gek.show.com;
        proxy_pass http://gek.show.com:8080;
    }
}
阿神阿神2754 days ago450

reply all(1)I'll reply

  • 黄舟

    黄舟2017-05-16 17:15:10

    It should be said that the first location will forward gek.show.com域名的80端口请求默认转发给http://localhost:1337/gek/去处理,如果请求的path符合第二个location的正则那么就会把请求转发给http://gek.show.com:8080去处理,比如说请求http://gek.show.com/okc/rest/test.html to the second location for processing.

    • ~ #The wavy line indicates performing a regular match, case-sensitive

    • ^~ will only match this rule, and nginx will stop searching for other matches, otherwise nginx will continue to process other location instructions

    reply
    0
  • Cancelreply