【问题标题】:WordPress blog subdirectory with Laravel on nginx produces 404 errornginx 上带有 Laravel 的 WordPress 博客子目录产生 404 错误
【发布时间】: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 与精确路径匹配。
  • 你的博客索引的实际路径是什么?

标签: wordpress laravel nginx


【解决方案1】:

假设您的index 文件实际上是.../blog.example.com/public/index.*,那么在您的location /blog 内,我相信您会想要将root 更改为alias。试试看是否有帮助。下面的文档更深入。如果您这样做,您可能希望删除该位置的try_files。我还会从 NGINX 浏览底部的链接,并根据这些建议检查您的配置。

NGINX Config

NGINX Alias Docs

【讨论】:

  • 当我使用alias 时出现错误No input file specified
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多