Wordpress 第二个子域重定向到主域,但URL与第二个域保持相同
很奇怪,看到这个问题的标题描述。详情如下: 1) 创建了一个带有“a1”的a记录。表示子域为:Wordpress 第二个子域重定向到主域,但URL与第二个域保持相同,wordpress,redirect,nginx,Wordpress,Redirect,Nginx,很奇怪,看到这个问题的标题描述。详情如下: 1) 创建了一个带有“a1”的a记录。表示子域为:a1.example.com 2) 由“sudo mkdir-p/var/www/a1.example.com/html/”创建的目录 3) 通过“sudo nano/etc/nginx/sites available/a1.example.com”创建服务器块 4) 在服务器块内部,核心部分: server { listen 80; listen [::]:80; root /var/www/a1.
a1.example.com
2) 由“sudo mkdir-p/var/www/a1.example.com/html/”创建的目录
3) 通过“sudo nano/etc/nginx/sites available/a1.example.com”创建服务器块
4) 在服务器块内部,核心部分:
server {
listen 80;
listen [::]:80;
root /var/www/a1.example.com/html;
index index.html index.htm;
server_name a1.example.com
location / {
try_files $uri $uri/ =404;
}
}
5) 创建链接:sudo ln-s/etc/nginx/sites available/a1.example.com/etc/nginx/sites enabled/
6) sudo nano/etc/nginx/nginx.conf
,取消注释:server\u names\u hash\u bucket\u size 64代码>
确保:include/etc/nginx/sites enabled/*代码>有吗
7) 重新启动的nginx:sudo服务nginx重新启动
棘手的部分:通过这样做,第一个子域a1.example.com
工作正常。
但是当我尝试创建第二个子域时,b2.example.com
按照上面的确切步骤,b2.example.com
根本不起作用:它将重定向到主页,但URL保持为b2.example.com
有什么不对劲
多谢各位
a1.example.com的配置
server {
listen 80;
listen [::]:80;
root /var/www/a1.example.com/html;
index index.php index.html index.htm;
server_name a1.example.com;
rewrite ^/archives/(\d+)$ http://a1.example.com/?p=$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
server {
listen 80;
listen [::]:80;
root /var/www/b2.example.com/html;
index index.php index.html index.htm;
server_name b2.example.com;
rewrite ^/archives/(\d+)$ http://b2.example.com/?p=$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
b2.example.com的配置
server {
listen 80;
listen [::]:80;
root /var/www/a1.example.com/html;
index index.php index.html index.htm;
server_name a1.example.com;
rewrite ^/archives/(\d+)$ http://a1.example.com/?p=$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
server {
listen 80;
listen [::]:80;
root /var/www/b2.example.com/html;
index index.php index.html index.htm;
server_name b2.example.com;
rewrite ^/archives/(\d+)$ http://b2.example.com/?p=$1 permanent;
location / {
try_files $uri $uri/ /index.php?q=$uri&args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/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;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
access.log中日志的一部分
[my IP address] - - [04/Feb/2016:00:11:05 -0500] "GET / HTTP/1.1" 200 147 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0"
[my IP address] - - [04/Feb/2016:00:11:05 -0500] "GET /favicon.ico HTTP/1.1" 404 142 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0"
[my IP address] - - [04/Feb/2016:00:11:08 -0500] "GET / HTTP/1.1" 200 17176 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0"
[my IP address] - - [04/Feb/2016:00:11:09 -0500] "GET /wp-includes/css/dashicons.min.css?ver=4.4.1 HTTP/1.1" 304 0 "http://b2.example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0"
[my IP address] - - [04/Feb/2016:00:11:09 -0500] "GET /wp-content/uploads/wp-less/themename/css/main-a800d37d44.css?ver=2.3.3 HTTP/1.1" 301 184 "http://b2.example.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0"
我注意到“304”和“301”,http状态。但仍然没有线索
curl-I b2.example.com:
HTTP/1.1200ok
服务器:nginx/1.8.1
日期:2016年2月4日星期四05:54:22 GMT
内容类型:text/html;字符集=UTF-8
连接:保持活力
X-Powered-By:PHP/5.5.9-1ubuntu4.14
设置Cookie:PHPSESSID=4r143k0o1m1l62p3g4vt1jrav1;路径=/
到期时间:1981年11月19日星期四格林威治标准时间08:52:00
缓存控制:无存储,无缓存,必须重新验证,后检查=0,预检查=0
Pragma:没有缓存
链接:;rel=”https://api.w.org/"
链接:;rel=短链接
curl-iA1.example.com
HTTP/1.1200ok
服务器:nginx/1.8.1
日期:2016年2月4日星期四05:54:32 GMT
内容类型:text/html;字符集=UTF-8
连接:保持活力
X-Powered-By:PHP/5.5.9-1ubuntu4.14
链接:;rel=”https://api.w.org/"
您是否检查了nginx的错误和访问日志?提示:*sudo nano…/…“没有创建目录。可能是输入错误。我想你的意思是*mkdir…/…”。谢谢semm0,是的,它是一个输入错误,应该是“sudo mkdir-p”,我现在就修改它。不管怎样,目录创建了alreadyOkay:)那么错误和访问日志呢?目录和其中文件的权限/所有者是否正确?权限/所有权,我所做的是:sudo chown-R www-data:www-data/var/www/b2.example.com/html/var/www/a1.example.com/htmlHi semm0,我用访问日志信息更新了。仍在努力找出问题所在