不知何故,我不确定如何,我们配置了一个充当开放代理的 nginx 反向代理。
日志文件告诉我们匹配的请求将针对以下conf
文件:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
access_log /var/log/nginx/access.p.log;
error_log /var/log/nginx/error.p.log;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_http_version 1.1;
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_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
server {
listen 80;
server_name ~first.*\.second\.com;
location / {
resolver 172.16.1.1 172.16.1.2;
proxy_pass http://$host;
proxy_read_timeout 7200s;
}
}
server {
listen 443;
server_name ~first.*\.second\.com;
ssl on;
location / {
resolver 172.16.1.1 172.16.1.2;
proxy_pass https://$host;
proxy_read_timeout 7200s;
}
}
顶级conf
文件如下所示:
用户 nginx;工人进程 8; pid /var/run/nginx.pid;
事件 {worker_connections 4096; # multi_accept on; }
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
这是什么原因造成的?
有关于 nginx 如何处理请求的文档。特别是这意味着如果您只有一个服务器块,那么所有请求都将在那里结束,而不管
Host
标头是否存在。在您的情况下,您只想处理与您的主机匹配的请求并忽略其他请求。所以你必须声明另一个服务器块来处理所有不匹配的请求。
这应该看起来像这样: