How to configure Nginx to serve Django and a Wordpress site on a specific route?

I have a Django app on a Hetzner server and a Wordpress site on a Hostinger server.

I want to configure Nginx on my Hetzner server to serve the Django app and when it requests the /route-name route, it serves a Wordpress site from the Hostinger server.

I've already allowed the IP address of my Hetzner server to access the Wordpress site.

Hetzner server is running Nginx and Hostinger is running Apache2 if that's relevant.

I know there are quite a few questions and answers regarding configuring Nginx to serve Django and Wordpress but I've been scouring this forum and the Internet for several hours now with no solution found for my problem. I suspect it may have to do with my Nginx config, but after trying out several configurations accepted on here and elsewhere, I can't seem to make it work.

This is what I currently have for my Nginx config:

server {
    location = /favicon.ico { access_log off; log_not_found off; }
    
    location /static/ {
        alias /var/www/example.com/static/;
    }

    location /media/ {
        alias /var/www/example.com/media/;
    }

    # Reverse proxy for /route-name
    location /route-name/ {
        proxy_pass http://<IP-ADDRESS OF HOSTINGER SERVER>/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    

    location / {
        include proxy_params;
        proxy_redirect off;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com www.example.com;
    return 404; # managed by Certbot
}
Вернуться на верх