doulan6245 2016-08-30 14:42
浏览 97

通过nginx重定向到wordpress博客

I am new to both, the nginx and the wordpress. I have configured my project to be served through the nginx server. Now we need to add the wordpress blog support to our project. My nginx is running over port 80. And the Apache is running over 8181 where my wordpress is installed.

Now any url going to blog is redirected to the apache over 8181 through my nginx server.

So below is my nginx redirect for the blog urls.

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;
        }

For the Google page speed insight, I did below config.

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

Now, the problem I am facing here is that, when some css or js request comes from the wordpress eg. http://192.168.1.54/blog/wp-content/themes/twentysixteen/style.css?ver=4.6 is getting caught inside the location config written for css ie. location ~* .(?:ico|css|js|gif|jpe?g|png|woff)$ Hence wordpress is not able to get the css or js.

So, I need your help where the any URL requested for blog on the nginx should be redirected to Apache server on 8181 port. Including the js and css. Where as other resource related url like https://192.168.1.54/js/somejs.js should also work.

I did some config change in wordpress file wp-config.php

define('WP_HOME', 'https://192.168.1.54/blog');
define('WP_SITEURL', 'https://192.168.1.54/blog');
  • 写回答

1条回答 默认 最新

  • dpda53918 2016-08-30 17:09
    关注

    You should use the ^~ modifier on the location /blog block to prevent conflict with regular expression location blocks at the same level. See this document for details.

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

    Also, you should probably remove the URL element from the proxy_pass directive, because it looks like you are mapping /blog to /blog anyway.

    And the proxy_redirect statement is back to front. But you probably do not need it as you have set WP_HOME/WP_SITEURL.

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退