【问题标题】:nginx loading assets but not showing for wordpress appnginx 加载资产但不显示 wordpress 应用程序
【发布时间】:2016-08-16 14:04:05
【问题描述】:

我正在使用以下设置在同一个域上运行 2 个应用程序。如果第一个应用程序返回 404,它会尝试另一个应用程序(/blog 上的 wordpress)。

location /blog {
    root /var/www/blog;
    index   index.html index.htm index.php;
    try_files $uri $uri/ /blog/index.php?$args;

    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}
location / {
    # ...
    proxy_intercept_errors on;
    recursive_error_pages on;
    error_page 404 =200 /blog/$uri;
}

每个页面都按预期加载,资产返回 200 和正确的内容。 但是这些资产的 css 和大多数图像都没有应用于页面,而一些工作正常。 包括以下内容:

include /etc/nginx/mime.types;

我知道这可能是一个糟糕的配置,但据我了解它应该仍然有效。 是否有其他配置可以实现类似的功能?

编辑: wordpress 安装位于 /var/www/blog/blog/

【问题讨论】:

    标签: css wordpress nginx http-status-code-404


    【解决方案1】:

    我不能完全理解这个问题,但我建议你把那个 php 块放在外面,并在 index.php uri 之后删除 blog 和 $args。

    试试这个,如果可行,请告诉我。 :)

    location /blog {
        root /var/www/blog;
        index   index.html index.htm index.php;
        try_files $uri $uri/ /index.php;
    }
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
    location / {
        # ...
        proxy_intercept_errors on;
        recursive_error_pages on;
        error_page 404 =200 /blog/$uri;
    }
    

    【讨论】:

    • 外部的 php 块无法正常工作。 $args 是 wordpress 工作所必需的,并且由于 wordpress 在 /var/www/blog/blog 中,因此需要博客。
    猜你喜欢
    • 2019-06-17
    • 1970-01-01
    • 2020-03-01
    • 2015-10-08
    • 1970-01-01
    • 2016-11-06
    • 2015-08-29
    • 1970-01-01
    • 2017-08-14
    相关资源
    最近更新 更多