admin管理员组

文章数量:1123869

I'm Alessio, and I'm facing an issue with the Nginx reverse proxy.

Here is the configuration file for the redirects:

# Nextcloud server configuration
server {
    listen 80;
    server_name nextcloud.example www.nextcloud.example;

    # Redirect from HTTP to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS traffic configuration (port 443)
server {
    listen 443 ssl;
    server_name nextcloud.example www.nextcloud.example;

    ssl_certificate /etc/nginx/sites-available/Cert/NextCloud/fullchain.pem;
    ssl_certificate_key /etc/nginx/sites-available/Cert/NextCloud/privkey.pem;

    # Reverse proxy configuration
    location / {
        proxy_pass https://192.168.1.65:443;
        proxy_set_header Host $host;  # Pass the original 'Host' header to the backend
        proxy_set_header X-Real-IP $remote_addr;  # Pass the client IP
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # Pass the previous IPs
        proxy_set_header X-Forwarded-Proto $scheme;  # Pass the protocol (http/https)
        proxy_cache_bypass $http_upgrade;  # Avoid cache for WebSocket or upgrade
    }
}

# HTTP traffic configuration (port 80)
server {
    listen 80;
    server_name passwordmanager.example www.passwordmanager.example;

    # Redirect from HTTP to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS traffic configuration (port 443)
server {
    listen 443 ssl;
    server_name passwordmanager.example www.passwordmanager.example;

    ssl_certificate /etc/nginx/sites-available/Cert/PasswordManager/fullchain.pem;
    ssl_certificate_key /etc/nginx/sites-available/Cert/PasswordManager/privkey.pem;

    # Reverse proxy configuration
    location / {
        proxy_pass https://192.168.1.8:443;
        proxy_set_header Host $host;  # Pass the original 'Host' header to the backend
        proxy_set_header X-Real-IP $remote_addr;  # Pass the client IP
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # Pass the previous IPs
        proxy_set_header X-Forwarded-Proto $scheme;  # Pass the protocol (http/https)
        proxy_cache_bypass $http_upgrade;  # Avoid cache for WebSocket or upgrade
    }
}

This works perfectly within my local network, but when I try to connect from the internet, I get redirected from

nextcloud.example 

to

passwordmanager.example

.

Has anyone experienced something similar or have suggestions on how to resolve this?

I tried placing the Reverse Proxy in the DMZ, but there was no change.

I also attempted to separate the code into two files, but still, nothing changed.

I'm Alessio, and I'm facing an issue with the Nginx reverse proxy.

Here is the configuration file for the redirects:

# Nextcloud server configuration
server {
    listen 80;
    server_name nextcloud.example.com www.nextcloud.example.com;

    # Redirect from HTTP to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS traffic configuration (port 443)
server {
    listen 443 ssl;
    server_name nextcloud.example.com www.nextcloud.example.com;

    ssl_certificate /etc/nginx/sites-available/Cert/NextCloud/fullchain.pem;
    ssl_certificate_key /etc/nginx/sites-available/Cert/NextCloud/privkey.pem;

    # Reverse proxy configuration
    location / {
        proxy_pass https://192.168.1.65:443;
        proxy_set_header Host $host;  # Pass the original 'Host' header to the backend
        proxy_set_header X-Real-IP $remote_addr;  # Pass the client IP
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # Pass the previous IPs
        proxy_set_header X-Forwarded-Proto $scheme;  # Pass the protocol (http/https)
        proxy_cache_bypass $http_upgrade;  # Avoid cache for WebSocket or upgrade
    }
}

# HTTP traffic configuration (port 80)
server {
    listen 80;
    server_name passwordmanager.example.com www.passwordmanager.example.com;

    # Redirect from HTTP to HTTPS
    return 301 https://$host$request_uri;
}

# HTTPS traffic configuration (port 443)
server {
    listen 443 ssl;
    server_name passwordmanager.example.com www.passwordmanager.example.com;

    ssl_certificate /etc/nginx/sites-available/Cert/PasswordManager/fullchain.pem;
    ssl_certificate_key /etc/nginx/sites-available/Cert/PasswordManager/privkey.pem;

    # Reverse proxy configuration
    location / {
        proxy_pass https://192.168.1.8:443;
        proxy_set_header Host $host;  # Pass the original 'Host' header to the backend
        proxy_set_header X-Real-IP $remote_addr;  # Pass the client IP
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # Pass the previous IPs
        proxy_set_header X-Forwarded-Proto $scheme;  # Pass the protocol (http/https)
        proxy_cache_bypass $http_upgrade;  # Avoid cache for WebSocket or upgrade
    }
}

This works perfectly within my local network, but when I try to connect from the internet, I get redirected from

nextcloud.example.com 

to

passwordmanager.example.com

.

Has anyone experienced something similar or have suggestions on how to resolve this?

I tried placing the Reverse Proxy in the DMZ, but there was no change.

I also attempted to separate the code into two files, but still, nothing changed.

Share Improve this question asked yesterday Alessio RestainoAlessio Restaino 1 New contributor Alessio Restaino is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

RESOLVED; Everything was correct; the issue was with the port configuration on the router. I had entered the wrong MAC address for the reverse proxy and was directly pointing to the server. That’s why I could only access it.

本文标签: