我将一个新的WordPress博客通过Forge安装到与Laravel 5.4应用程序相同的服务器上。为简单起见,我将博客放在blog.example.com
中,但我没有任何实际指向子域的DNS。相反,我希望example.com/blog
指向我的WordPress安装。
然后我修改了Laravel网站的nginx conf文件,如下所示:
# 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错误。
我的做法有什么问题?
答案 0 :(得分:0)
假设您的index
文件实际上是.../blog.example.com/public/index.*
,那么在location /blog
内,我相信您需要将root
更改为alias
。试试看,看看是否有帮助。以下文件更深入。如果您这样做,您可能希望摆脱该位置的try_files
。我还会浏览NGINX底部的链接,并根据这些建议检查您的配置。