gpt4 book ai didi

nginx $server_name 始终是本地主机

转载 作者:行者123 更新时间:2023-12-04 16:47:12 32 4
gpt4 key购买 nike

我有一个在 AWS EC2 实例上运行的 nginx 1.4.5 服务器。我有两个 conf 文件:default.confmyapp.confdefault.conf 监听 localhost,myapp.conf 监听 myapp.mydomain.com

但是我发现即使我在浏览器中输入 myapp.mydomain.com,它总是会加载 default.conf。我更改了 nginx.conf 文件中的 log_format 添加了一个 "$server_name" 字段来检查每个请求的服务器名称。我发现它总是 localhost

有人对此有任何想法吗?

配置信息更新

nginx.conf

server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
...
}

myapp.conf

 server {
listen 80;
server_name myapp.mydomain.com;

access_log /var/log/nginx/myapp.log;

location / {
add_header P3P 'CP="CAO PSA OUR"';
proxy_pass http://127.0.0.1:8080/myapp/;
set $ssl off;
if ($scheme = https) {
set $ssl on;
}
proxy_set_header X-Forwarded-Ssl $ssl;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}

是的,我在两道防火墙后面,一道是 iptable,另一道是 AWS 内置的安全组

最佳答案

有人拥有 similar problem通过以下方式修复:

I've fixed this now, in case anyone has the same problem as me it was to do with "server_names_hash_bucket_size 64;" in /etc/nginx/nginx.conf.

That line was commented out by default so I uncommented and restarted nginx and it works fine now.

关于nginx $server_name 始终是本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22157608/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com