簡體   English   中英

nginx 反向代理重定向到內部 ip 地址

[英]nginx reverse proxy redirects to internal ip address

我有一個 nginx 作為反向代理服務器和 apache 到服務器 nextcloudpi web 應用程序。

我有以下 nginx 配置

server {

server_name drive.example.com;

location / {
proxy_pass http://192.168.0.7/;
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/drive.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/drive.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 = drive.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


listen 80;
listen [::]:80;

server_name drive.example.com;
    return 404; # managed by Certbot


}

以下為 apache 配置

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    DocumentRoot /var/www/nextcloud
ServerName drive.example.com
    CustomLog /var/log/apache2/nc-access.log combined
    ErrorLog  /var/log/apache2/nc-error.log
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/drive.example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/drive.example.com/privkey.pem
  </VirtualHost>
  <Directory /var/www/nextcloud/>
    Options +FollowSymlinks
    AllowOverride All
    <IfModule mod_dav.c>
      Dav off
    </IfModule>
    LimitRequestBody 0
    SSLRenegBufferSize 10486000
  </Directory>
</IfModule>

Note: Previously, i had apache as the direct front end to the internet and now i want to use nginx as the front end and apache still as the web application server

如果我可以在不重定向到內部 ip 地址的情況下到達 drive.example.com,任何幫助都將不勝感激?

謝謝你。

看來您需要禁用代理重定向標頭,嘗試更改和更新 nginx(反向代理)的配置文件,這將確保您的nginx作為ZB6EFD606D118D0F62066E314客戶端和服務器之間的中間人運行( nginx 只是通過重定向將客戶端卸載到 apache 服務器而不充當中間人):

server {
listen 80;
listen [::]:80; # if you're not using ipv6 do remove this line.    
server_name drive.example.com;

location / {
    proxy_redirect              off;
    proxy_read_timeout          1m;
    proxy_connect_timeout       1m;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_redirect off;
    proxy_pass http://192.168.0.7/;    
}

    listen [::]:443 ssl; # if you're not using ipb6 do remove this line
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/drive.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/drive.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 = drive.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot




server_name drive.example.com;
    return 404; # managed by Certbot   
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM