Report this

What is the reason for this report?

How can I configure two droplets using nginx proxy_pass?

Posted on 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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.