# Pritunl problem admin panel behind Nginx

**URL:** <https://forum.pritunl.com/t/pritunl-problem-admin-panel-behind-nginx/1704>\
**Category:** Pritunl VPN\
**Tags:** pritunl\
**Created:** [January 18, 2024, 2:48pm UTC](https://forum.pritunl.com/t/pritunl-problem-admin-panel-behind-nginx/1704 "2024-01-18T14:48:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubavb](https://forum.pritunl.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lubavb](https://forum.pritunl.com/u/lubavb)\
**Post date:** [January 18, 2024, 2:48pm UTC](https://forum.pritunl.com/t/pritunl-problem-admin-panel-behind-nginx/1704/1 "2024-01-18T14:48:22Z")

</div>

Hello, I want to hide the admin panel behind Nginx on port 8443, but this scheme does not work. I receive a non-working page on port 443, but I can access the admin console via [https://mydomain.com:8443](https://mydomain.com:8443)

The directive was indicated in different ways  
proxy\_pass [https://127.0.0.1:8443](https://127.0.0.1:8443);  
proxy\_pass [http://127.0.0.1:8443](http://127.0.0.1:8443);  
proxy\_pass [https://mydomain8443](https://mydomain8443);  
The directive was indicated in different ways  
proxy\_pass [https://127.0.0.1:8443](https://127.0.0.1:8443);  
proxy\_pass [http://127.0.0.1:8443](http://127.0.0.1:8443);  
proxy\_pass [https://192.168.2.76:8443](https://192.168.2.76:8443);

pritunl set app.reverse\_proxy true, pritunl set app.server\_ssl false then pritunl set app.server\_port 8443

For example conf which nginx:  
server {  
listen 80 ;

```
root /usr/share/pritunl/www;
server_name mydomain.com;

location / {

  return 301 https://$host$request_uri;
 }

```

}

server {  
listen 443 ssl http2;  
ssl\_protocols TLSv1.2 TLSv1.3;  
ssl\_ciphers  
‘ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384’;  
ssl\_prefer\_server\_ciphers off;  
ssl\_certificate /etc/ssl/mydomain.com.crt;  
ssl\_certificate\_key /etc/ssl/mydomain.com.key;  
server\_name [mydomain.com](http://mydomain.com);  
location / {  
proxy\_pass [https://mydomain:8443](https://mydomain:8443);  
proxy\_ssl\_verify off;  
proxy\_redirect default;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-Proto $scheme;  
proxy\_max\_temp\_file\_size 0;  
# proxy\_set\_header X-Nginx-Proxy true;  
add\_header Strict-Transport-Security “max-age=31536000; includeSubDomains” always;  
add\_header X-Frame-Options “SAMEORIGIN”;  
add\_header Content-Security-Policy “default-src ‘self’; font-src \*;img-src \* data:; script-src \*; style-src \*”;  
add\_header X-XSS-Protection “1; mode=block” always;

#this is the maximum upload size  
client\_max\_body\_size 10m;  
client\_body\_buffer\_size 128k;

```
  proxy_connect_timeout 90;
  proxy_send_timeout 90;
  proxy_read_timeout 90;
  proxy_buffering off;
  proxy_request_buffering off; # Required for HTTP CLI commands
  proxy_set_header Connection ""; # Clear for keepalive

```

}

This is what the page looks like on port 443 via Nginx

 ![image](https://forum-static.pritunl.com/original/1X/3b46d3defe00dd3a4cd58c61267587040883040f.png)  
thanks.

---

<div class="post-metadata">

**Author:** ![zach](https://forum.pritunl.com/user_avatar/forum.pritunl.com/zach/32/1105_2.png) [@zach](https://forum.pritunl.com/u/zach)\
**Post date:** [January 19, 2024, 12:31am UTC](https://forum.pritunl.com/t/pritunl-problem-admin-panel-behind-nginx/1704/2 "2024-01-19T00:31:39Z")

</div>

It’s likely one of the header modifications is preventing the page from rendering correctly. Open Chrome Developer Tools to check for errors.

You are also mixing HTTP and HTTPS configurations. The nginx server can be configured to forward to HTTPS. Run the commands below to configure the Pritunl server to use SSL.

```auto
sudo pritunl set app.reverse_proxy true
sudo pritunl set app.redirect_server false
sudo pritunl set app.server_ssl true
sudo pritunl set app.server_port 8443

```

Below is an nginx configuration, replace `demo.pritunl.com` and `123.123.123.123`. If the configuration is copied the `\$` escaping for the `tee` command needs to be removed and replaced with `$`.

```auto
sudo openssl req -x509 -nodes -days 18250 -newkey rsa:2048 -keyout /etc/nginx/ssl/notfound.key -out /etc/nginx/ssl/notfound.crt

sudo tee /etc/nginx/nginx.conf << EOF
user nginx;
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 400000;
pcre_jit on;

events {
    worker_connections 20000;
    multi_accept on;
    use epoll;
}

http {
    server_tokens off;
    charset utf-8;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    access_log off;
    client_header_timeout 45;
    client_body_timeout 45;
    keepalive_timeout 65;
    connection_pool_size 1024;
    request_pool_size 8k;
    client_header_buffer_size 2k;
    client_body_buffer_size 32k;
    server_names_hash_bucket_size 512;
    server_names_hash_max_size 1024;
    types_hash_max_size 2048;

    server {
        listen 80;
        listen [::]:80;
        server_name _;
        return 404;
    }

    server {
        listen 443 ssl;
        listen [::]:443 ssl;
        ssl_certificate /etc/nginx/ssl/notfound.crt;
        ssl_certificate_key /etc/nginx/ssl/notfound.key;
        server_name _;
        return 404;
    }

    include /etc/nginx/conf.d/*.conf;
}
EOF

sudo tee /etc/nginx/conf.d/pritunl-vpn.conf << EOF
upstream pritunl-vpn {
    server 123.123.123.123:8443;
}

server {
    listen 80;
    listen [::]:80;
    root /usr/share/nginx/html;
    server_name demo.pritunl.com;
    location / {
        return 301 https://demo.pritunl.com\$request_uri;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /etc/nginx/ssl/demo.pritunl.com.crt;
    ssl_certificate_key /etc/nginx/ssl/demo.pritunl.com.key;
    server_name demo.pritunl.com;
    location / {
        proxy_pass https://pritunl-vpn;
        proxy_ssl_verify off;
        proxy_set_header Host \$http_host;
        proxy_set_header X-Forwarded-For \$remote_addr;
        proxy_set_header X-Real-IP \$remote_addr;
    }
}
EOF

```

The certificate paths above will need to either use the `certbot` script below or another certificate configured at that path.

```auto
sudo dnf -y install certbot

sudo tee /etc/systemd/system/certbot.target << EOF
[Unit]
Description=Cerbot target
StopWhenUnneeded=yes
EOF

sudo tee /etc/systemd/system/certbot.timer << EOF
[Unit]
Description=Cerbot timer

[Timer]
OnCalendar=*-*-* 8:00:00
Unit=certbot.target

[Install]
WantedBy=basic.target
EOF

sudo tee /etc/systemd/system/certbot.service << EOF
[Unit]
Description=Cerbot
Wants=certbot.timer

[Service]
ExecStart=/usr/bin/certbot-nginx

[Install]
WantedBy=certbot.target
EOF

sudo tee /usr/bin/certbot-nginx << EOF
#!/bin/bash

getcert () {
  echo "Getting certificate email=\$1 domain=\$2"
  /usr/bin/certbot --webroot --agree-tos --non-interactive --webroot-path /usr/share/nginx/html --preferred-challenges http --email \$1 -d \$2 certonly
  /usr/bin/cp -f /etc/letsencrypt/live/\$2/fullchain.pem /etc/nginx/ssl/\$2.crt
  /usr/bin/chown nginx:nginx /etc/nginx/ssl/\$2.crt
  /usr/bin/cp -f /etc/letsencrypt/live/\$2/privkey.pem /etc/nginx/ssl/\$2.key
  /usr/bin/chown nginx:nginx /etc/nginx/ssl/\$2.key
}

getcert "contact@pritunl.com" "demo.pritunl.net"

/usr/bin/chown -R nginx:nginx /etc/nginx/ssl
/usr/bin/chmod 600 /etc/nginx/ssl/*
/usr/sbin/restorecon -R -v /etc/nginx
/usr/bin/systemctl reload nginx
EOF
sudo chmod +x /usr/bin/certbot-nginx

```

Generate the initial certificate and start the server.

```auto
sudo /usr/bin/certbot-nginx

sudo systemctl daemon-reload
sudo systemctl enable certbot.service
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer

sudo systemctl restart nginx
sudo systemctl enable nginx

```

---

<div class="post-metadata">

**Author:** ![lubavb](https://forum.pritunl.com/letter_avatar_proxy/v4/letter/l/a698b9/32.png) [@lubavb](https://forum.pritunl.com/u/lubavb)\
**Post date:** [January 22, 2024, 1:15pm UTC](https://forum.pritunl.com/t/pritunl-problem-admin-panel-behind-nginx/1704/3 "2024-01-22T13:15:33Z")

</div>

Your change didn’t help me, the page didn’t open either, but after reading the errors from the browser console, I was inspired to think that it wouldn’t be a bad idea to have it statically look at the directory and here’s the working server config via nginx. I’ll share it here so as not to waste time.

server {  
listen 80;  
nginx /usr/share/pritunl/www;  
server\_name [vpn.demo.com](http://vpn.demo.com);

# location /.well-known {

# allow all;

# }

```
location / {
  return 301 https://vpn.demo.com$request_uri;
}

```

}

server {  
listen 443 ssl http2;  
ssl\_protocols TLSv1.2 TLSv1.3;  
ssl\_ciphers  
‘ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384’;  
ssl\_prefer\_server\_ciphers on;  
ssl\_certificate /etc/nginx/ssl/vpn.demo.com.crt;  
ssl\_certificate\_key /etc/nginx/ssl/vpn.demo.com.key;  
server\_name [vpn.demo.com](http://vpn.demo.com);

# include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

# ssl\_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

```
location / {

```

# auth\_basic “Restricted”;

# auth\_basic\_user\_file /etc/nginx/.htpasswd;

```
   proxy_pass https://127.0.0.1:8443;
    proxy_ssl_verify off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_max_temp_file_size 0;
 
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
    add_header X-Frame-Options "SAMEORIGIN";

    add_header X-XSS-Protection "1; mode=block" always;
 }

```

location /css {  
alias /usr/share/pritunl/www/css;  
}

```
location /js {
    alias /usr/share/pritunl/www/js;
}

```

location /fonts {  
alias /usr/share/pritunl/www/fonts;  
}  
}  
thanks
