我们在不同路径的根域的子文件夹中安装了 wordpress,即使在该位置使用 root,wordpress 安装仍然加载域站点的根。
server {
listen 80;
server_name domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name domain.com;
ssl on;
#ssl_certificate /var/www/certs/star.domain.com.cert;
#ssl_certificate_key /var/www/certs/star.domain.com.key;
ssl_certificate /var/www/certs/cert_chain.crt;
ssl_certificate_key /var/www/certs/__domain_com.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
return 301 https://www.$server_name$request_uri;
}
server {
## Default Server Settings
include /etc/nginx/basic.conf;
listen 443 ssl;
server_name www.domain.com;
access_log /var/log/nginx/domain.access.log;
error_log /var/log/nginx/domain.error.log;
root /var/www/domain/current;
index index.php index.html;
ssl on;
#ssl_certificate /var/www/certs/star.domain.com.cert;
#ssl_certificate_key /var/www/certs/star.domain.com.key;
ssl_certificate /var/www/certs/cert_chain.crt;
ssl_certificate_key /var/www/certs/__domain_com.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
error_page 404 /index.php;
location / {
try_files $uri $uri/ $uri.php?$query_string;
}
location /blog {
root /var/www/;
try_files $uri $uri/ /blog/index.php?q=$request_uri;
}
location ~ /blog/.+\.php$ {
try_files $uri $uri/ /blog/index.php?q=$request_uri =404;
include /etc/nginx/fastcgi_params.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
Run Code Online (Sandbox Code Playgroud)
这是对域根目录的 curl 请求:
[root@callloop-web-1 www]# curl -IL callloop.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:31:27 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: https://callloop.com/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:31:27 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: https://www.callloop.com/
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:31:28 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: PHPSESSID=3obiecqr3rm4i1q1bas8rcripdfuv8ru; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Run Code Online (Sandbox Code Playgroud)
和访问日志:
104.236.27.189 - - [21/Apr/2017:19:31:28 +0000] "HEAD / HTTP/1.1" 200 0 "-" "curl/7.29.0"
Run Code Online (Sandbox Code Playgroud)
现在是子文件夹:
[root@callloop-web-1 www]# curl -IL callloop.com/blog
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:33:27 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: https://callloop.com/blog
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:33:27 GMT
Content-Type: text/html
Content-Length: 184
Connection: keep-alive
Location: https://www.callloop.com/blog
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:33:27 GMT
Content-Type: text/html
Content-Length: 184
Location: https://www.callloop.com/blog/
Connection: keep-alive
HTTP/1.1 404 Not Found
Server: nginx/1.6.3
Date: Fri, 21 Apr 2017 19:33:27 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: PHPSESSID=1lo0hrgkcrsrtstlldnr8gr3o2vu20if; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Run Code Online (Sandbox Code Playgroud)
访问日志
104.236.27.189 - - [21/Apr/2017:19:33:27 +0000] "HEAD /blog HTTP/1.1" 301 0 "-" "curl/7.29.0"
104.236.27.189 - - [21/Apr/2017:19:33:27 +0000] "HEAD /blog/ HTTP/1.1" 404 0 "-" "curl/7.29.0"
Run Code Online (Sandbox Code Playgroud)
所以你可以看到 404,这是有道理的,但我不知道为什么
您root的location ~ /blog/.+\.php$块中缺少一个语句。但是,如果嵌套位置块,您可能会发现更容易阅读:
location ^~ /blog {
root /var/www/;
try_files $uri $uri/ /blog/index.php?q=$request_uri;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params.conf;
fastcgi_pass 127.0.0.1:9000;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4272 次 |
| 最近记录: |