主站:example.com
位于/var/www/example.com
。
Wordpress 博客:example.com/blog
在/var/www/blog
。
无法让它工作。
server {
listen 80;
server_name example.com;
root /var/www/example.com;
# Add index.php to the list if you are using PHP
index Index.html index.html index.htm index.nginx-debian.html;
location ~* \.(ico|jpg|jpeg|png|gif|swf|css|json|txt|sd|html)$ {
try_files $uri =404;
access_log off;
expires 1d;
}
location ~* \.(js)$ {
gzip_static on;
gunzip on;
try_files $uri =404;
access_log off;
expires 1d;
}
location /blog {
alias /var/www/blog/;
#try_files $uri $uri/ /index.php?q=$request_uri;
try_files $uri $uri/ @blog;
location ~ \.php$ {
fastcgi_split_path_info ^(.*\.php)(.*)$;
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
#fastcgi_index index.php;
#include the fastcgi_param setting
include fastcgi_params;
}
}
location @blog {
rewrite ^/blog(.*) /blog/index.php?q=$1;
}
}
忘http://example.com/blog
了403 Forbidden
。看起来alias
不适用于try_files
。
但即使http://example.com/blog/index.php
不起作用。得到了File not found.
。