Welcome! Log In Create A New Profile


Other port from router to Nginx 443 port

Posted by esingress 
Other port from router to Nginx 443 port
October 20, 2021 12:08AM
Hi all,

I'm trying to configure a Nginx reverse proxy with virtual domain to Nextcloud Server

here is my setting

Router (
Nginx (
Nextcloud Server (
Since I don't want use 443 port, I set up a port forward in router. Router (port: 12345) -> Nginx (port: 443)



worker_processes 1;

events {
worker_connections 1024;

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

# Redirect all HTTP traffic to HTTPS
server {
listen 80 default_server;
listen [::]:80 default_server;

return 301 https://$host$request_uri;

server {
listen 443 ssl http2;

server_name 'nextcloud.test.com';
access_log /var/log/nginx/cloud.access.log;
error_log /var/log/nginx/cloud.error.log;

include snippets/nextcloud.test.com.cert.conf;

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-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;

location / {
include snippets/proxy-params.conf;

location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;

location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;

client_max_body_size 1999M;




It works fine. if I direct port forward 443 to Nginx server.

When I type "https://nextcloud.test.com" in browser, it will redirect to "https://nextcloud.test.com/index.php/apps/dashboard/" <- the Nextcloud main page

But if I set router port 12345 forward to Nginx server port 443. It will not work.

When I type "https://nextcloud.test.com:12345" in browser, it still redirect to "https://nextcloud.test.com/index.php/apps/dashboard/" since it missing the port ":12345" in url, it cannot access the Nextcloud main page. The main page will work if I manual type "https://nextcloud.test.com:12345/index.php/apps/dashboard/"

Any idea?


Edited 1 time(s). Last edit at 10/20/2021 12:08AM by esingress.
Re: Other port from router to Nginx 443 port
October 20, 2021 03:07AM
Temp. method.

proxy_set_header X-Forwarded-Host $server_name; -> proxy_set_header X-Forwarded-Host $server_name:12345;
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 108
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready