繁体   English   中英

在与Rails应用程序相同的域上运行Wordpress的最佳方法是什么?

[英]What's the best way to run Wordpress on the same domain as a Rails application?

我有一个标准的Rails应用程序,Nginx和Mongrel运行在http:// mydomain 我需要在http://mydomain.com/blog上运行Wordpress博客。 我的偏好是在同一服务器或单独的盒子上运行Apache的博客,但我不希望用户在URL中看到不同的服务器。 这是可能的,如果没有,你会建议你做什么?

实际上,既然你正在使用Nginx,那么你已经处于良好的状态并且不需要Apache。

您可以通过fastcgi运行PHP(有关于如何在Nginx wiki中执行此操作的示例),并在Nginx配置中使用URL匹配模式将某些URL定向到Rails,将其他URL定向到PHP。

这是一个用于通过PHP fastcgi运行WordPress博客的示例Nginx配置(注意我还提到了Nginx等效的WordPress .htaccess,因此您也将使用已经使用此配置的花哨URL):

server {
    listen       example.com:80;
    server_name  example.com;
    charset      utf-8;
    error_log    /www/example.com/log/error.log;
    access_log   /www/example.com/log/access.log  main;
    root         /www/example.com/htdocs;

    include /www/etc/nginx/fastcgi.conf;
    fastcgi_index index.php;

    # Send *.php to PHP FastCGI on :9001
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9001;
    }

    # You could put another "location" section here to match some URLs and send
    # them to Rails. Or do it the opposite way and have "/blog/*" go to PHP
    # first and then everything else go to Rails. Whatever regexes you feel like
    # putting into "location" sections!

    location / {
        index index.html index.php;
        # URLs that don't exist go to WordPress /index.php PHP FastCGI
        if (!-e $request_filename) {
            rewrite ^.* /index.php break;
            fastcgi_pass 127.0.0.1:9001;
        }

    }
}

这是我在上面的配置中包含的fastcgi.conf文件(我把它放在一个单独的文件中,所以我的所有虚拟主机配置文件都可以包含在正确的位置,但你不必这样做):

# joelhardi fastcgi.conf, see http://wiki.codemongers.com/NginxFcgiExample for source
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
#fastcgi_param  REDIRECT_STATUS    200;

我也碰巧做了Nginx维基建议的事情,并使用Lighttpd的spawn-fcgi作为我的CGI-spawner(Lighttpd是一个非常快速的编译,没有奇怪的依赖,所以安装快速简便),但你也可以为此使用一个简短的shell / Perl脚本。

我认为joelhardi的解决方案优于以下方案。 但是,在我自己的应用程序中,我喜欢将博客保留在与Rails站点不同的VPS上(内存问题分离)。 要使用户看到相同的URL,您使用通常用于代理到杂项群集的相同代理技巧,除了您代理到另一个框上的端口80(或其他)。 十分简单。 对于用户来说,它与代理mongrel一样透明 - 他们只“看到”NGINX在您域中的端口80上做出响应。

upstream myBlogVPS {
        server 127.0.0.2:80;  #fix me to point to your blog VPS
}

 server {
    listen       80;


    #You'll have plenty of things for Rails compatibility here

    #Make sure you don't accidentally step on this with the Rails config!

    location /blog {
        proxy_pass         http://myBlogVPS;
        proxy_redirect     off;

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

你可以使用这个技巧让Rails与你想要的任何服务器技术一起玩。 直接代理到相应的服务器/端口,NGINX将其隐藏在外部世界。 此外,由于URL将全部引用同一个域,因此只要您正确编写URL,就可以无缝地集成基于PHP的博客,基于Python的跟踪系统和Rails应用程序。

如果您在EC2 / AWS环境中,Nginx现在提供了执行此操作的脚本

它可能很容易适应您的情况。 它非常方便。

上面的答案非常适合你的问题。

另一种FCGI将是使用php-fpm。 文档有点稀疏,但效果很好。

在我看来,像重写操纵器这样的东西会做你想要的。 对不起,我没有更多细节 - 只是大声思考:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM