【发布时间】:2015-04-17 17:29:21
【问题描述】:
我的 nginx 服务器上有 3 个不同的站点,每个站点都有自己的服务器块。为了安全起见,我将只使用 domain1.com、domain2.com 和 domain3.com 而不是真正的域。 Domain3 仍在等待转让给我的所有权,因此它根本无法运行。
问题是每当您访问 domain1.com 时,它都会将我转发到 domain2.com。据我所知,没有任何东西说 domain1.com 应该转发到 domain2.com。我清除了我的 DNS 缓存以及所有浏览器缓存和 cookie。
这里是 domain1.com 的 server_block 配置
#This is for redirecting everyone from www.domain.com to domain.com
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name www.domain1.com;
return 301 https://domain1.com$request_uri;
}
server {
#listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;
listen 443;
server_name domain1.com;
#keepalive_timeout 70;
root /var/www/domain1.com/html;
index index.php index.html index.htm;
ssl on;
ssl_certificate /etc/nginx/ssl/domain1.com/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/domain1.com/ssl.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/domain1.com/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
domain2.com配置如下:
#This is for redirecting everyone from www.domain.com to domain.com
server {
listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 ipv6only=on; ## listen for ipv6
server_name www.domain2.com;
return 301 https://domain2.com$request_uri;
}
server {
#listen 80;
#listen [::]:80 ipv6only=on;
listen 443;
server_name domain2.com;
ssl on;
ssl_certificate /etc/nginx/ssl/domain2.com/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/domain2.com/ssl.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
root /var/www/domain2.com/html;
index index.php index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/domain2.com/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
根据nginx -t 没有配置问题。任何帮助将不胜感激!
【问题讨论】:
-
当您在尝试访问其他域时重定向到错误域时,请发布
access.log条目。它发生在 http 和 https 上吗? -
@DmitryVerkhoturov 这里是access.log pastebin的链接
标签: nginx configuration server