我有一些复杂的服务配置。
我的域(现在称为“a.team”)指向我的 1&1 云服务器,其中包含运行 dockerized 功能齐全的不同服务以及 dockerized nginx。许多子域指向 docker 容器,一切都很好。
现在我在办公室有一台服务器,端口 8080、8090 和 7990(Atlassian 产品)可以通过路由器 fw 和静态 ip 访问(工作正常)。
我希望云服务器像这样管理域和代理:
SSL https://jira.a.team到非 SSL http://---.---.---.133:8080 (虚拟)作为代理(以及其他产品)
Nginx 配置为将所有 http 重定向到 https:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 default_server ssl;
server_name _;
ssl_certificate /path/bundle.cer;
ssl_certificate_key /path/-.a.team_private_key.key;
}
我想将新配置添加到现有配置中。
server {
listen 443 ssl;
server_name jira.a.team;
location / {
proxy_pass http://---.---.---.133:8080;
proxy_redirect off;
}
}
我尝试了很多与主机、x-real-ip 和 x-forwarded-for 的代理集 header 的组合,但我得到的只是 504 网关超时。
谢谢你的帮助!
问候
最佳答案
尝试使用 Nginx 中的上游功能。
不过你应该知道,当代理传递到外部地址时,你需要允许传出流量到你办公室固件中的这些端口,因为流量将通过 Nginx 服务器。
配置服务器(vhost jira.a.team),注意上游引用jira_app
server {
listen *:443 ssl;
server_name jira.a.team;
ssl on;
ssl_certificate ....
ssl_certificate_key ....
ssl_session_cache ....
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ....
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/....access.log combined;
error_log /var/log/nginx/....error.log;
location / {
proxy_pass http://jira_app;
proxy_read_timeout 90;
proxy_connect_timeout 90;
proxy_redirect off;
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 Proxy "";
}
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
配置上游
upstream jira_app {
server ---.---.---.133:8080 fail_timeout=10s;
}
如果您仍想使用从 HTTP 到 HTTPs 的重定向,您可以将以下操作作为一个单独的服务器对象:
server {
listen *:80;
server_name jira.a.team;
location / {
rewrite ^ https://jira.a.team$request_uri? permanent;
}
}
关于redirect - Nginx 配置代理传递给外部 ip 和端口 (https -> http),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41426617/