1

I have a domain where I have a wildcard A record to a IP (61.61.61.61) (not under my control).

Because I wanted some pages on the domain to be under my control, I thought it was easy to proxy all data through nginx. But looks like this isn't the same behaviour. Instead when I try to load the main index of the site that was displaying correctly before, it's redirecting me to another site now.

I think this is because nginx is not proxying all data or is not forwarding some headers.

I configured nginx this way

server {
    server_name test.com;
    root /var/www/test.com/;
    index  index.html index.htm index.php;

    merge_slashes on;

    location /landers {
        if (!-e $request_filename) {
            rewrite ^.*$ /index.php last;
        }
    }

    location / {
        proxy_pass http://61.61.61.61:80;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        # edit below to fix config display
        fastcgi_param SCRIPT_FILENAME /var/www/test.com$fastcgi_script_name;
    }
}

The request is not reconginzed on the 3th party server, this is probably why it is redirecting me to another site on that server.

[Edit]

So to be more clear. I want the url /landers to be hosted on my machine. That's why I have a different location in nginx for that.

The rest of the requests to the test.com should go to the correct IP address (and handled by the 3th party server).

Everything was working fine when I had the IP address as an A-record. But now nginx proxies the request and I get a 301 redirect back (from the server with IP 61.61.61.61).

Normally I shouldn't get a 301 back but rather the proxied page. That's why I guess that the request to the 61.61.61.61 server is somewhat different than going directly (using A-records instead of proxying to that server). This makes me think that the proxied HTTP request is somewhat different than the not proxied version, so that the 61.61.61.61 server can't match the correct vhost on their server.

Hope this makes things a bit more clear.

3
  • Can you edit your question to further define "some pages" so you more precisely state your needs - what needs to be proxied where, what you need under your control, etc. Also please provide more detail on exactly what is wrong, what errors you get - error/access logs and such.
    – Tim
    Mar 28, 2016 at 20:43
  • Edited the page a bit, hopefully things are more clear now. If not, let me know. Mar 28, 2016 at 20:53
  • It's a bit more clear. I think you need to do some basic problem solving. curl the target machine from the nginx server to prove it works, curl from a second machine directly and via nginx. If it doesn't work update your post to include access and error logs for the applicable request.
    – Tim
    Mar 28, 2016 at 21:06

0

You must log in to answer this question.

Browse other questions tagged .