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
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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>?
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?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.