首页 文章

通过nginx重定向到wordpress博客

提问于
浏览
0

我是nginx和wordpress的新手 . 我已经将我的项目配置为通过nginx服务器提供服务 . 现在我们需要为我们的项目添加wordpress博客支持 . 我的nginx正在通过端口80运行 . 而Apache正在运行8181,我的wordpress已安装 .

现在,任何访问博客的网址都会通过我的nginx服务器重定向到8181上的apache .

以下是我的博客网址的nginx重定向 .

location /blog {
            proxy_pass http://127.0.0.1:8181/blog/;
            proxy_redirect https://192.168.1.54 http://127.0.0.1:8181/blog;

            proxy_read_timeout       3500;
            proxy_connect_timeout    3250;

            proxy_set_header   X-Real-IP          $remote_addr;
            proxy_set_header   Host               $host;
            proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto  https;

            proxy_set_header   SSL_PROTOCOL $ssl_protocol;
            proxy_set_header   SSL_CLIENT_CERT $ssl_client_cert;
            proxy_set_header   SSL_CLIENT_VERIFY $ssl_client_verify;
            proxy_set_header   SSL_SERVER_S_DN $ssl_client_s_dn;
        }

对于Google页面速度洞察,我做了以下配置 .

location ~* \.(?:ico|css|js|gif|jpe?g|png|woff)$ {
            expires 30d;
            add_header Pragma public;
            add_header Cache-Control "public";
        }

现在,我面临的问题是,当一些css或js请求来自wordpress时,例如 . http://192.168.1.54/blog/wp-content/themes/twentysixteen/style.css?ver=4.6被抓到为css编写的位置配置即 . location ~ .(?:ico|css|js|gif|jpe?g|png|woff)$* 因此wordpress无法获得css或js .

所以,我需要你的帮助,在nginx上为 blog 请求的任何URL应该被重定向到8181端口上的Apache服务器 . 包括js和css . 像https://192.168.1.54/js/somejs.js这样的其他资源相关网址也应该起作用 .

我在wordpress文件中做了一些配置更改 wp-config.php

define('WP_HOME', 'https://192.168.1.54/blog');
define('WP_SITEURL', 'https://192.168.1.54/blog');

1 回答

  • 0

    您应该在 location /blog 块上使用 ^~ 修饰符,以防止与同一级别的正则表达式位置块冲突 . 有关详细信息,请参阅this document .

    location ^~ /blog {
        proxy_pass http://127.0.0.1:8181;
        ...
    }
    

    此外,您应该从 proxy_pass 指令中删除URL元素,因为无论如何您看起来都在将 /blog 映射到 /blog .

    proxy_redirect 声明又回到了前面 . 但是你可能不需要它,因为你已经设置了WP_HOME / WP_SITEURL .

相关问题