我的 nginx 配置有问题。我在同一台服务器上有多个虚拟主机。但是,我试图添加另一个虚拟主机,这是一个 SSL 网站。返回的域名网站不正确。
如果我将 listen 443 改为 listen 80,则正确的网站会恢复。我不明白为什么会发生这种情况。任何帮助都将不胜感激,谢谢。
以下是所讨论的 vhost 的配置。
虚拟主机配置
server {
listen 443 ssl default_server;
server_name *.website.com;
root /var/www/vhost/www.website.com/public_html/httpdocs/;
index index.php;
ssl_certificate /etc/nginx/ssl/www.website.com/website.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.website.com/website.com.key;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_hide_header X-Powered-By;
}
}
nginx.config
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# 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;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
##
# Size Limit
##
client_max_body_size 2M;
}
答案1
您是否有多个启用了 SSL 的虚拟主机?我认为它们都是相同的 IP,并且您正在尝试使用不支持 SNI 的东西进行检查,因此域名不用于选择正确的虚拟主机。所以请发布整个配置文件和日志。也许答案就在那里。