How can I configure two droplets using nginx proxy_pass?

December 1, 2013 3.4k views
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
2 Answers
Try replacing $scheme with http, restart nginx, does it work? If not, what do you see when you try to browse to /preview/wordpress?
The http change doesn't solve anything. The main server is working completely fine, when you go to /preview/wordpress 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.

Let me ask this differently. How can I setup one server to answer the requests at example.org and, if and only if the user opens example.org/preview/wordpress, show a WordPress blog stored in the other server?
Have another answer? Share your knowledge.