0

I want to proxy a example1.com to example2.com with nginx, configure as fllow

server
{
    listen 80;
    server_name www.example1.com;
    location / {
    expires off;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_cache_use_stale off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://www.example2.com/;
    }
    access_log /var/log/nginx/www.example1.com_access.log;
    error_log /var/log/nginx/www.example1.com_error.log;
}

later I change to use example3.com:

server
    {
        listen 80;
        server_name www.example1.com;
        location / {
        expires off;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_cache_use_stale off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://www.example3.com/;
        }
        access_log /var/log/nginx/www.example1.com_access.log;
        error_log /var/log/nginx/www.example1.com_error.log;
    }

Whatever I restart nginx, it will proxy www.example1.com to www.example2.com, not www.example3.com. Who has ever meet this question?

Nginx version:1.8.0

2 Answers 2

1

Your Nginx syntax is correct, so your problem is elsewhere. Some things to check:

  1. Do the domains resolve where you expect?

    • dig +short www.example2.com
    • dig +short www.example3.com
  2. Are "www.example2.com" and "www.example3.com" on the same server? The problem could be with /that/ server configuration?

  3. Make sure it's not some sort of browser caching issue. Use curl or another command-line HTTP testing tool that doesn't have a cache.

Sign up to request clarification or add additional context in comments.

1 Comment

As you've said, the problem is elsewhere.I have found it and it had been solved, thank you
0

Have you restarted your nginx server? try sudo pkill nginx and then sudo nginx

1 Comment

I have try sudo pkill nginx then sudo nginx, but it doesn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.