Nginx reverser proxy to vm

Current Development version likely to have breaking changes
Post Reply
frypan
Posts: 2
Joined: Sun Nov 03, 2019 4:09 pm

Nginx reverser proxy to vm

Post by frypan »

I am running an Nginx reverse proxy to a system in a DMZ that is running Zoneminder on an ubuntu 20.04 system. If I access the zoneminder site through the IP address everything works great. I also have https working. No problem. Next I tried to set up an Nginx reverse proxy server so that I can access the zoneminder system from outside of my network with my own domain. If I access the the domain.
https://zm.mydomain.com

I see the default Apache Ubuntu page but if I go to
https://zm.mydomain.com/zm

The URL is replaced with the ip address of the system on the lan and is not https any more either.
I am thinking that this has to be something in the apache setting on the zoneminder system since I can get to the default page OK.
I have done a lot of googling around but there are no keywords that seem to fit my issue. It looks like there was something like this years ago in index.php and ZM_BASE_URL but that is commented out now.

This has to be something really simple but I am stumped.

Here is the configuration that I have in Nginx. Note that <zm lan ip address> is the ip address of the zm machine on my lan.

Code: Select all

server {
    server_name zm.mydomain.com;


    location / {
        proxy_set_header Host $host;
        proxy_pass http://<zm lan ip address>;
    }


    ssl on;
    keepalive_timeout 60;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/zm.mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/zm.mydomain.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


}
frypan
Posts: 2
Joined: Sun Nov 03, 2019 4:09 pm

Re: Nginx reverser proxy to vm

Post by frypan »

So after struggling a bit I figured out that my problems were all Nginx related this is not the appropriate forum for this. (Sorry). But for the most part I got the reverse proxy working. I don't understand Nginx enough to fix this but the URL requires a "/" on the end for this to work with this configuration. Like "http://zm.<domain>.com/zm/" not "http://zm.<domain>.com/zm"

Code: Select all

upstream zoneminder {
        server <IP of ZM server>:443 fail_timeout=0;
}

server {
    listen 80;
    listen [::]:80;
    server_name zm.<domain>.com; # replace this with your domain
    return 301 $scheme://$server_name$request_uri;
}

server  {
    listen 443 ssl;
    #listen [::]:443;

    server_name zm.<domain>.com;

    ssl_certificate /etc/letsencrypt/live/zm.<domain>.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/zm.<domain>.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

    location / {
        proxy_pass https://zoneminder;
    }

    location  /zm/ {
        proxy_pass https://zoneminder/zm/;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        proxy_http_version    1.1;
        proxy_set_header      Upgrade $http_upgrade;
        proxy_set_header      Connection 'upgrade';
        proxy_set_header      Host $host;
        proxy_set_header      X-Real-IP            $remote_addr;
        proxy_set_header      X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header      X-NginX-Proxy    true;
        proxy_cache_bypass    $http_upgrade;
    }

}
Wsassg
Posts: 1
Joined: Mon Dec 05, 2022 3:44 am

Re: Nginx reverser proxy to vm

Post by Wsassg »

Based on what you've described, it sounds like you may not have the correct proxy settings configured in your Apache configuration file.
Post Reply