500 error due to improper nginx proxy configuration

Source: Internet
Author: User

The Error 500 is displayed when you access the website. You can view the log to obtain the error message:

2012/12/06 16:10:52 [alert] 11679#0: *9189 1024 worker_connections are not enough while connecting to upstream, client: 127.0.0.1, server: xxx.netingcn.com, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:80/", host: "xxx.netingcn.com"

For the above errors, many people mentioned on the Internet that most of the cases are caused by too many concurrency in the production environment. The solution is to modify the worker_connections value in the configuration file and increase it. However, if a proxy is configured in nginx on the local machine and no external access is provided, the above error is prompted. The problem is not solved by trying to modify worker_connections. The proxy configuration is roughly as follows:

server {    listen       80;    server_name  yyy.netingcn.com;    location / {        root   /var/www/netingcn.com;        index  index.html index.php;    }}server {    listen       80;    server_name  xxx.netingcn.com;    location / {        proxy_pass              http://yyy.netingcn.com/;        proxy_set_header        X-Real-IP $remote_addr;        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header        Host $http_host;    }}

The original purpose was to delegate all requests to xxx.netingcn.com to yyy.netingcn.com. You may wonder why it is so troublesome to add xxx.netingcn.com directly to the first server_name. Here is just an example. Because of the special circumstances in the formal environment, it is not possible to configure the configuration, so all will think of using the proxy method.

The 500 error caused by the above configuration can certainly be ruled out because worker_connections is too small. After careful configuration, we find that "proxy_set_header Host $ http_host;" is the culprit because it causes an endless loop, when requesting xxx, because the proxy is sent to yyy, nginx was originally handed over to server yyy for processing, but the host in the header is still xxx. nginx finds xxx according to server_name in the configuration, therefore, an infinite loop is displayed, and the error mentioned above will be reported. If the problem has been located, it is easy to solve. Just remove proxy_set_header Host $ http_host; this line of configuration will work.


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.