【发布时间】:2018-09-09 05:18:42
【问题描述】:
我通过 Forge 将一个新的 WordPress 博客安装到与 Laravel 5.4 应用程序相同的服务器上。为简单起见,我将博客放在blog.example.com,但实际上我没有任何 DNS 指向子域。相反,我想让 example.com/blog 指向我的 WordPress 安装。
然后我修改了 Laravel 站点的 nginx 配置文件,如下所示:
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/before/*;
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
root /home/forge/example.com/current/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/example.com/230815/server.crt;
ssl_certificate_key /etc/nginx/ssl/example.com/230815/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'SHA-HASH-HERE';
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;
fastcgi_connect_timeout 600;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
location ~ /\.(?!well-known).* {
deny all;
}
location /blog {
root /home/forge/blog.example.com/public;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
access_log /var/log/nginx/blog.example.com-access.log;
error_log /var/log/nginx/blog.example.com-error.log error;
}
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/example.com/after/*;
我重新启动了 nginx,希望在访问 example.com/blog 时看到 WP 安装,但我只看到来自 Laravel 应用程序的 404 错误。
我的方法有什么问题?
【问题讨论】:
-
试一试
location = /blog与精确路径匹配。 -
你的博客索引的实际路径是什么?