Nginx reverse proxy for port issues

Source: Internet
Author: User

Nginx reverse proxy about port problem http://www.cnblogs.com/likehua/p/4056625.html

Nginx Default reverse port is 80, so there is a port of 80 after the agent problem, which causes access error. The main reason is that the host configuration of the Nginx configuration file does not have a response port set.

The relevant configuration files are as follows:

1234 proxy_pass http://ime-server/ime-server;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  

As above, the host is configured with only host, there is no corresponding port, which causes the wrong ports to be obtained at the proxy location. This article takes Java as an example:

12345 string scheme = Httprequest.getscheme ( );      string serverName = Httprequest.getservername ();      int  port = Httprequest.getserverport ();      //Service Request address      string RequestUri = scheme+ "://" +servername+ +port+ "/ime-server/rest/" +servicename+ "/wmts"

At this point, the port obtained is 80, although the Nginx listener is 9090. The mistake made me very depressed. Then, modify the Nginx configuration file, the host after the change to $host: $server _port, the configuration file is as follows:

12345678 location /ime-server {            #root   html;            #index  index.html index.htm;            proxy_pass http://ime-server/ime-server;            proxy_set_header Host $host:$server_port;            proxy_set_header X-Real-IP $remote_addr;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        }

Restart Nginx,./nginx-s Reload. Then check that the port information after the agent is correct:

Nginx reverse proxy for port issues

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.