nginx - 我在尝试在 Nginx 中为在 localhost 中运行的应用程序配置反向代理时遇到问题
问题描述
我在运行 Ubuntu v18.04.4 LTS 的 Digital Ocean 液滴上设置了翼手龙。大约一年前,我与 Nginx 一起设置了它,设置了 A 记录(panel.example.com),它与 Let's Encrypt SSL 证书一起工作得很好。
几天前,我决定设置The Lounge,一个自托管的 Web IRC 客户端。默认情况下,它在端口 9000 上运行。我按照他们推荐的说明,更改了人们在他们的帮助 IRC 频道上推荐的一些内容。与翼手龙面板不同,我希望它出现在我的个人域中。因此,我将我的 A 记录设置为指向我的 DO 液滴,其主机值为irc
,因此它将显示在irc.yash.gg
。然后我使用 acme.sh 在独立模式下生成 Let's Encrypt 密钥。然后,我将下面的配置添加到/etc/nginx/sites-available/thelounge.conf
,符号链接到/etc/nginx/sites-enabled/thelounge.conf
. 但由于某种原因,使用下面的配置,它开始重定向到“你已经正确设置了 nginx”页面。而现在,几天后,我被引导到 panel.sneakycraft.com 上的翼手龙小组。
我完全迷路了,我不明白发生了什么。我真的很感激这方面的一些帮助。请让我知道,如果我可以提供任何其他信息来帮助诊断此问题。
谢谢!
server {
listen 80;
listen [::]:80;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name irc.yash.gg;
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] valid=300s;
resolver_timeout 5s;
charset utf-8;
location ^~ /irc/ {
proxy_pass https://127.0.0.1:9000/;
proxy_ssl_protocols TLSv1.2 TLSv1.3;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
# by default nginx times out connections in one minute
proxy_read_timeout 1d;
# proxy_redirect http://127.0.0.1:9000 https://irc.yash.gg;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/thelounge.app-access.log;
error_log /var/log/nginx/thelounge.app-error.log error;
# allow larger file uploads and longer script runtimes
client_max_body_size 100m;
client_body_timeout 120s;
sendfile off;
# SSL Configuration
ssl_certificate /etc/letsencrypt/live/irc.yash.gg/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/irc.yash.gg/privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_trusted_certificate /etc/letsencrypt/live/irc.yash.gg/fullchain.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
# See https://hstspreload.org/ before uncommenting the line below.
# add_header Strict-Transport-Security "max-age=15768000; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header Content-Security-Policy "frame-ancestors 'self'";
add_header X-Frame-Options DENY;
add_header Referrer-Policy same-origin;
# location ~ \.php$ {
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass unix:/run/php/php7.2-fpm.sock;
# fastcgi_index index.php;
# include fastcgi_params;
# fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param HTTP_PROXY "";
# fastcgi_intercept_errors off;
# fastcgi_buffer_size 16k;
# fastcgi_buffers 4 16k;
# fastcgi_connect_timeout 300;
# fastcgi_send_timeout 300;
# fastcgi_read_timeout 300;
# }
location ~ /\.ht {
deny all;
}
}
解决方案
休息室绑定到我的公共 IP。将配置更改为指向 serverip:port 而不是 localhost 并且有效。
推荐阅读
- python-3.x - 两个分类列的熊猫中的分组计数 - 熊猫
- c++ - 如何让我的程序停止出现构建问题并停止使用负数?
- java - 你能检查一下输入是否与变量名相同吗?
- java - 迭代方法列表并获取第一个非空响应
- scheme - SICP 练习 1.17 问题
- visual-studio-code - 无法通过 VS Code 连接到 Azure Cosmos 数据库
- forms - Symfony 动态 EntityType 数据属性
- visual-studio-code - vscode 扩展:弃用警告`Buffer()`,如何诊断
- json - 解码 JSON 问题。swift中的keyNotFound错误消息
- python - 意外的 Python 打印 Unicode 输出