我一直试图弄清楚将近6个月的时间,我不知所措。我已经读过每一篇关于堆栈溢出的文章,甚至与我的问题有关,也没什么用。我有一台机器运行redmine和bookstack。我在该机器上有nginx并配置为使用redmine.home.mydomain.com和kb.home.mydomain.com,这很有效。当我输入它时没有问题。
当我输入尝试从面向外部的nginx服务器重定向到该URL时,我遇到的问题。我有redmine.mydomain.com和kb.mydomain.com。 redmine一个很好用,但kb一个重定向到redmine。我无法弄清楚原因。
我已在多个浏览器中检查了响应标头,并将其重定向到https://kb.mydomain.com,但该调用的响应是redmine主页。即使它应该重定向到kb.home.mydomain.com,如果我直接键入它,它工作正常。
Bookstack配置
# redirect to ssl
server {
listen 80;
listen [::]:80;
server_name kb.mydomain.com www.kb.mydomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name kb.mydomain.com www.kb.mydomain.com;
client_max_body_size 50M;
ssl on;
ssl_certificate /etc/letsencrypt/live/mydomain.com-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com-0001/privkey.pem;
access_log /var/log/nginx/kb.access;
error_log /var/log/nginx/kb.error;
location / {
proxy_pass http://kb.home.mydomain.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
redmine config。
# redirect to ssl
server {
listen 80;
listen [::]:80;
server_name redmine.mydomain.com www.redmine.mydomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name redmine.mydomain.com www.redmine.mydomain.com;
client_max_body_size 50M;
ssl_certificate /etc/letsencrypt/live/mydomain.com-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com-0001/privkey.pem;
location / {
proxy_pass http://redmine.home.mydomain.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
我迷失了为什么它会重定向到redmine任何帮助都会非常感激。
答案 0 :(得分:0)
这种情况正在发生,因为您需要在后端环境中设置正确的标头HTTP主机,如何做错,您甚至已经进入默认网站。
server {
listen 80;
listen [::]:80;
server_name kb.mydomain.com www.kb.mydomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name kb.mydomain.com www.kb.mydomain.com;
client_max_body_size 50M;
ssl on;
ssl_certificate /etc/letsencrypt/live/mydomain.com-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com-0001/privkey.pem;
access_log /var/log/nginx/kb.access;
error_log /var/log/nginx/kb.error;
location / {
proxy_pass http://kb.home.mydomain.com/;
proxy_set_header Host kb.home.mydomain.com;
proxy_set_header X-Real-IP $remote_addr;
}
}
redmine config。
server {
listen 80;
listen [::]:80;
server_name redmine.mydomain.com www.redmine.mydomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name redmine.mydomain.com www.redmine.mydomain.com;
client_max_body_size 50M;
ssl_certificate /etc/letsencrypt/live/mydomain.com-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com-0001/privkey.pem;
location / {
proxy_pass http://redmine.home.mydomain.com;
proxy_set_header Host redmine.home.mydomain.com;
proxy_set_header X-Real-IP $remote_addr;
}
}