gpt4 book ai didi

redirect - nginx 301 重定向到不正确的虚拟主机

转载 作者:太空宇宙 更新时间:2023-11-03 14:51:29 27 4
gpt4 key购买 nike

尽管预期受影响的站点位于它们自己的服务器 block 中,但我遇到了指向我们主站点的多个站点的 301 重定向问题。如果我禁用主站点,其他站点将按预期工作,因此主配置中的某些内容似乎胜过其他站点。任何帮助将不胜感激。

/etc/nginx/nginx.conf:

user nginx;
worker_processes 8;
worker_rlimit_nofile 100000;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 4096;
multi_accept on;
use epoll;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log;
access_log off;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1100;
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;
open_file_cache max=2000 inactive=20s;
open_file_cache_valid 60s;
open_file_cache_min_uses 5;
open_file_cache_errors off;
client_max_body_size 50M;
client_body_buffer_size 1m;
client_body_timeout 15;
client_header_timeout 15;
keepalive_timeout 2 2;
send_timeout 15;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
fastcgi_buffers 256 16k;
fastcgi_buffer_size 128k;
fastcgi_connect_timeout 3s;
fastcgi_send_timeout 120s;
fastcgi_read_timeout 120s;
fastcgi_busy_buffers_size 256k;
fastcgi_max_temp_file_size 0;
reset_timedout_connection on;
server_names_hash_bucket_size 100;
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
include /etc/nginx/conf.d/*.conf;
}

这是似乎胜过其他虚拟主机的虚拟主机配置文件。/etc/nginx/conf.d/site1.conf:

server {
listen 10.10.10.1:80;
listen 10.10.10.1:443 ssl;
server_name ^site1\.org$ ^www\.site1\.org$ ^old\.site1domain\.org$;
ssl_certificate ...;
ssl_certificate_key ...;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
keepalive_timeout 70;
root /var/www/vhosts/site1.org/httpdocs;
index index.php;
client_max_body_size 128M;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm/site1.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi_params;
include /etc/nginx/fastcgi.conf;
open_file_cache max=4000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
}
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
if ($scheme != "https") {
rewrite ^ https://site1.org$uri permanent;
}
if ($host != "site1.org") {
rewrite ^ https://site1.org$uri permanent;
}
#wp-super-cache
....
location ~* .(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|tar|mid|midi|wav|bmp)$ {
expires max;
}

呸。好的,这里是一个不同的虚拟主机配置的示例,它似乎没有响应请求(相反,我得到一个 301 到上面的虚拟主机,有或没有重定向被注释掉)。

/etc/nginx/conf.d/site2.conf:

server  {
listen 10.10.10.1:80;
server_name ^sub1\.site2\.org$;
allow all;
proxy_redirect / http://10.10.10.1:6969;
location / {
proxy_pass http://10.10.10.1:6969;
}
}

但是,出于某种原因,此 SSL 代理按预期工作(在不同的 IP 上):/etc/nginx/conf.d/site3.conf:

server  {
listen 10.10.10.2:443 ssl;
server_name ^sub3\.site1\.org$;
ssl_certificate ...;
ssl_certificate_key ...;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
allow all;
proxy_redirect / http://sub3.site1.org:80/;
location / {
proxy_pass http://sub3.site1.org:80/;
}
proxy_set_header Host $http_host;
}

这是我尝试连接到 http://sub1.site2.org 时得到的结果:

[c09 79]/etc/nginx/conf.d # wget {sub1.site2.url}--2015-11-25 09:09:28-- {sub1.site2.url}正在解析 sub1.site2.org... 10.10.10.1正在连接到 sub1.site2.org|10.10.10.1|:80... 已连接。已发送 HTTP 请求,正在等待响应... 301 永久移动位置:{site1.url} [以下]

等等...提前致谢。

最佳答案

您的server_name 指令都是无效的,因此它们都不匹配。所以 nginx 默认使用第一个 server 容器,并通过它处理所有请求。

然后它命中您的rewrite ^ https://site1.org$uri permanent; conditional rewrite。

如果您必须在您的server_name 中使用正则表达式(尽管除非您确实需要它否则效率较低),您必须在名称前加上~。否则,只需使用普通名称即可。

server_name site1.org www.site1.org old.site1domain.org;

参见 this document了解详情。

关于redirect - nginx 301 重定向到不正确的虚拟主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33918931/

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