nginx small slash in proxy_pass

nginx small slash in proxy_pass

1. Story Background

I believe doing micro-channel public number of friends all know that the development, in order to preview the micro-channel effect, you must use the domain names. Many of my friends use within the network penetration tool. Not only does not work well is not stable. So, play face thick to eat the world's attitude , the company applied for a sub-domain it points to a 80-port aliyun ecs's. but later, the port is not enough. in line with the principle of proximity, IT has found little brother, again a kindly remapping 8080. On that day playfully little brother a look of disdain eyes looking at me, I'm sorry subdomain only 80 port is not coincidence, my ecs only open port 80. At this point there is only one domain name, I want to map multiple servers Yes when the nginx release amplifier. very simple demands

  1. Access demo.herbert.com/dev1/json.do mapping network addresses 192.168.10.2:8080/dev1/json.do
  2. Within access demo.herbert.com/dev2/xxx.html mapping network address 192.168.10.2:8081/xxx.html

2. solve the problem trilogy, test and document search

View the official document, we choose tengine official translation of the document in page [module reference catalog] find [ngx_http_proxy_module] link, after clicking into the search proxy_pass. Will find the following two notes

  • If proxy_pass URI used, when a transfer request to the backend server, the request path after normalization with the mating part of the path configuration is replaced URI defined in command:
location /name/ {
    proxy_pass http://127.0.0.1/remote/;
}
  • If you are not using proxy_pass URI, sent to the back-end server request URI is generally initiated by the client's original URI, if nginx change request URI, the URI is delivered complete standardization URI after nginx change:
location /some/path/ {
    proxy_pass http://127.0.0.1;
}

This explanation obscure, there was even a lot of people do not know the name of the URI of the , of course, I am also that a lot of people, and I searched the URI of the the URL of a difference, have popped up during a URN , have a big head, see ten minutes did not find a satisfactory answer. tentatively I think it is a part of the address bar.

The first point simple appreciated, if the configuration values back proxy_pass containing / , resulting paths, path location configuration will be removed, and then the contents may be present after the binding location address configuration request. Combination of both into a new address. According to the official configuration. we assume

  • The domain name is nginx access wx.464884492.com
  • Address user access is wx.464884492/name/herbert/

According to a first configuration provides, nginx schematic real address obtained as follows:

Finally, there is a schematic diagram of a slash

The second point then simple to understand, if the configuration values proxy_pass back does not contain / , the path after the path finally obtained, arranged proxy_pass value plus location and configuration path. Both combined into a new address, the configuration provided by the official, we assume that

  • The domain name is nginx access wx.464884492.com
  • Address user access is wx.464884492/some/path/herbert/

The second configuration provides, nginx schematic real address obtained as follows:

Finally, no slash schematic

So that is a brief summary

  • If proxy_pass configuration values comprise / to remove matching path portion
  • If proxy_pass configuration values do not include / to retain the matching path portion

3. Verify results

Nginx from the official website to download the file unzip modify nginx.conf http modules are as follows:

...
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    client_max_body_size   20M;
    server {
        listen       80 default_server;
        server_name  127.0.0.1;
        location / {  
            proxy_pass http://127.0.0.1;
        }
        location /name/  {
            proxy_pass http://127.0.0.1/remote/;
        }
        location /some/path/ {
           proxy_pass http://127.0.0.1;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
...

Double-click nginx.exe run separate visits at the address in the browser

Since I did not configure specific root, the final address to access the page can not be found, so a page error page An error occurred will appear, but we just can confirm our previous results in the error log. Our top of the schematic using domain names way of illustration, if the result of the schematic want, you need to add the configuration file in the host wx.464884492.com 127.0.0.1while the change in the profile server_name nginxwx.464884492.com

Open error.log log file logs directory, we find that information and finally converted real address information we were told, just visit the show where the main information is as follows:

浏览器访问 http://127.0.0.1/name/herbert/
nginx 给我的访问日志
2019/12/06 14:21:32 [alert] 15384#12716: *9206 1024 worker_connections are not enough while connecting to upstream, 
client: 127.0.0.1, server: 127.0.0.1, 
request: "GET /remote/herbert/ HTTP/1.0", 
upstream: "http://127.0.0.1:80/remote/herbert/", host: "127.0.0.1"

浏览器访问 http://127.0.0.1/some/path/herbert/
nginx 给我的访问日志
2019/12/06 14:21:35 [alert] 15384#12716: *11251 1024 worker_connections are not enough while connecting to upstream, 
client: 127.0.0.1, server: 127.0.0.1, 
request: "GET /some/path/herbert/ HTTP/1.0", 
upstream: "http://127.0.0.1:80/some/path/herbert/", host: "127.0.0.1"

4. solve the problem

I have more knowledge of the demands on the perfect solution.

  • demo.herbert.com/dev1/json.do mapping the network address 192.168.10.2:8080/dev1/json.do

The corresponding configuration

location /dev1/ {  
 proxy_pass http://192.168.10.2:8080;
}
  • Within access demo.herbert.com/dev2/xxx.html mapping network address 192.168.10.2:8081/xxx.html

The corresponding configuration

location /dev2/ {  
 proxy_pass http://192.168.10.2:8081/;
}

5. Summary

Consultation rather than summary no harm, in fact so much more than a word, there are bars removed, no bars reservation , though small, but a lot of steps to resolve.

I welcome interested friends concerned about the micro-channel subscription number, "small hospital no small", or click on the two-dimensional code concerns below. I will be difficulties encountered in development for many years, as well as some interesting features, the experience will be 11 to publish my subscription number. Need paper nginx configuration file can reply in public No. nginx1

Micro-channel attention [small] is not a small hospital

Nothing else to do, using cocos creator has developed a small game, interested friends can play a

Game Tank Man

There are technologies like chat friends are also welcome into the group, if the failure of the two-dimensional code can add my reply letter micro front end

Micro-channel group

Guess you like

Origin www.cnblogs.com/yfrs/p/nginxproxypass.html