Home  >  Q&A  >  body text

nginx upstream proxy_pass problem

What are the differences between the following configurations?

upstream baidu_server {
    server 180.149.132.47:80;
}
server {
    listen 80;
    server_name  xxx.example.com;
    charset utf-8;
    access_log off;

    location / {
        proxy_redirect off;
        proxy_pass http://baidu_server;
        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header Accept-Encoding "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
server {
    listen 80;
    server_name  xxx.example.com;
    charset utf-8;
    access_log off;

    location / {
        proxy_redirect off;
        proxy_pass http://180.149.132.47:80;
        proxy_set_header User-Agent $http_user_agent;
        proxy_set_header Accept-Encoding "";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

The second one can jump to the Baidu homepage correctly, but the first one does not. Why?

伊谢尔伦伊谢尔伦2713 days ago467

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 17:23:19

    Baidu server rejects, you can set other tests

    reply
    0
  • 某草草

    某草草2017-05-16 17:23:19

    Both are fine.

    reply
    0
  • PHPz

    PHPz2017-05-16 17:23:19

    Owner, I also encountered this problem. Please give me an answer or solution. The first URL directly becomes http://baidu_server

    reply
    0
  • Cancelreply