【问题标题】:nginx-apache-wordpress: setup apache/wordpress under subdirectory and behind nginxnginx-apache-wordpress:在子目录下和 nginx 后面设置 apache/wordpress
【发布时间】:2013-03-11 23:21:37
【问题描述】:

我开发了一个 Rails 应用程序并且对它很满意,但我被要求在子目录 /wp 下设置 Wordpress。在尝试使 nginx-to-apache 代理工作的一些不愉快的时间之后,我放弃了从糟糕的指南中复制代码并编写了一些非常简短而清晰的配置:

location @wp {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_redirect off;
  proxy_pass http://127.0.0.1:8080;
}

location ~ ^/wp(/|$) {
  root /home/apache/www;
  rewrite ^/wp/?$ / break;
  rewrite ^/wp/(.*) /$1 break;
  try_files $uri @wp;
}

它解决了我遇到的大部分问题,但它不起作用,原因很明显: Wordpress 生成<real_ip>:8080/<url> 链接,这不仅丑陋(我可以忍受),而且链接不起作用,因为 Apache 仅在 localhost 上侦听。 如何告诉 Apache 或 Wordpress(或者我应该使用 Nginx 代理什么标头)使链接看起来像 <real_ip>/wp/<url>?还是我的设置设计有问题?我将不胜感激任何解决方案或提示,谢谢!

【问题讨论】:

    标签: wordpress apache nginx rewrite subdirectory


    【解决方案1】:

    下面是我对 nginx 的配置,它在主根目录下运行 Rails 应用程序,在子目录下运行 WordPress 博客。也许试试这个?

    server {
      listen <ip-address>:80;
      server_name domain.com;
      rewrite ^(.*)$ $scheme://www.domain.com$request_uri? permanent;
      break;
    }
    
    server {
      listen <ip-address>:80;
      server_name www.domain.com;
      root   /www/domain.com/public_html/current/public;
    
      access_log /www/domain.com/logs/access.log;
      error_log /www/domain.com/logs/error.log;
    
      location ^~ /blog {
        root /www/domain.com/blog/public_html;
        index index.php index.html index.htm;
        try_files $uri $uri/ /blog/index.php?$args;
    
        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            if ($uri !~ "^/images/") {
                    fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
            }
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/domain.com/blog/public_html$fastcgi_script_name;
       }
    }
    

    【讨论】:

    • 你能提供你包含的/etc/nginx/fascgi_paramsfile的内容吗?我真的无法让它与它一起工作。
    猜你喜欢
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 2018-11-23
    • 2012-06-30
    相关资源
    最近更新 更多