Nginx Reverse proxy port problems

Source: Internet
Author: User
Tags nginx reverse proxy
: This article mainly introduces the port issue of Nginx Reverse proxy. if you are interested in the PHP Tutorial, please refer to it. The default reverse port of Nginx is 80, so there is a problem of port 80 after the proxy, which leads to an access error. The main reason is that no response port is set when the host of The Nginx configuration file is configured.
The configuration files are as follows:

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 shown above, the Host configuration only has a host and no corresponding port, which leads to an incorrect port in the proxy. This article takes java as an example:

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 time, the obtained port is 80, although the nginx listening port is 9090. This error made me very depressed. Modify the nginx configuration file and change the configuration file behind the Host to $ host: $ server_port. the configuration file is as follows:

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 whether the port information after the proxy is correct.

The above describes the port issue of Nginx Reverse proxy, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

Related Article

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.