Question

How can I configure two droplets using nginx proxy_pass?

  • Posted December 1, 2013

I’m having a lot of trouble understanding how nginx deals with proxy_pass and, after hours of breaking things, it seems that I can’t do what I want.

I have two servers with different IP. One will serve a python application, and the other, a WordPress website.

The first server answers all the requests to http://www.example.org, so the configuration looks like this:

server {
    listen 80;
    server_name example.org *.example.org;
    return 301 $scheme://www.example.org$request_uri;
}

server {
    listen 80;
    server_name www.example.org;

    location / { try_files $uri @application; }

    location @application {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:4242;
    }

    location /preview/wordpress {
        proxy_pass $scheme://192.168.0.10;
        proxy_set_header Host $host;
    }
}

Everything looks and works just fine. The only question I have here is what is the difference between proxy_pass $scheme://192.168.0.10; and proxy_pass $scheme://192.168.0.10/; with the trailing slash?

The other server should answer requests from http://www.example.org/preview/wordpress. The configuration looks like this:

server {
    listen 80;
    server_name www.example.org;

    root /srv/www/example.org;
    index index.php;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location /preview/wordpress {
        alias /srv/www/example.org;
        try_files $uri $uri/ /preview/wordpress/index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_split_path_info ^(/preview/wordpress)(/.*)$;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}

I’m pretty sure that the error is in this configuration file. I don’t know what location blocks should I use to handle the requests made by the other server. I really appreciate if anyone can give me an 101 class about nginx proxy_pass

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

The <code>http</code> change doesn’t solve anything. The main server is working completely fine, when you go to <code>/preview/wordpress</code> it pass the request to the other server. I’m having problems handling the passed requests at the second server. Sometimes it shows me a forbidden error or a 404 error. <br> <br>Let me ask this differently. How can I setup one server to answer the requests at <code>example.org</code> and, if and only if the user opens <code>example.org/preview/wordpress</code>, show a WordPress blog stored in the other server?

Try replacing <code>$scheme</code> with <code>http</code>, restart nginx, does it work? If not, what do you see when you try to browse to <code>/preview/wordpress</code>?