Nginx Reverse proxy port domain name cannot be accessed problem solved

Source: Internet
Author: User
Tags nginx reverse proxy
The first day of work in the morning to solve the problem, it is really the first time to meet. Using the domain name Proxy Web project, when requested, I do not know why the domain name is not used, but the direct IP port as the path, causing the Web page crashes unusable.

Because Nginx is used as the front-end server, a little bit of modification is made, and the following are the pre-and post-modification comparisons:

Before modification:

server {
Listen 80;
server_name xxx.aaaaa.com;
Location/{
proxy_pass http://10.148.22. 81: 8180;
Proxy_set_header X-real-ip $remote _addr;
Index index.html index.htm;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}

After modification:

server {
Listen 80;
server_name xxx.aaaaa.com;
Location/{
Proxy_pass http://10.148.22. 81: 8180;
Proxy_read_timeout 600s;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header Host $host: $server _port;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Index index.html index.htm;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}

The access was successful.

Of course it is recommended for static resources, such as

Location ~. *\. (gif|jpg|png|html|htm|css|js|flv|ico|swf) (.*) {
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_cache Cache_one;
Proxy_cache_valid 302 1h;
Proxy_cache_valid 301 1d;
Proxy_cache_valid any 1m;
Expires 30d;
Index index.html index.htm;
} the efficiency is better.

The main reference is the original, thank the elder brother guidance:

Http://www.cnblogs.com/likehua/p/4056625.html

The contents are as follows:

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:

1

2

3

4

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:

1

2

3

4

5

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:

1

2

3

4

5

6

7

8

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:

The above describes the Nginx reverse proxy port domain name can not be accessed to solve the problem, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.