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

后端 未结 5 1717
悲&欢浪女
悲&欢浪女 2021-02-05 17:36

I\'ve got a standard Rails app with Nginx and Mongrel running at http://mydomain. I need to run a Wordpress blog at http://mydomain.com/blog. My preference would be to host th

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 18:19

    I think joelhardi's solution is superior to the following. However, in my own application, I like to keep the blog on a separate VPS than the Rails site (separation of memory issues). To make the user see the same URL, you use the same proxy trick that you normally use for proxying to a mongrel cluster, except you proxy to port 80 (or whatever) on another box. Easy peasy. To the user it is as transparent as you proxying to mongrel -- they only "see" the NGINX responding on port 80 at your domain.

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

    You can use this trick to have Rails play along with ANY server technology you want, incidentally. Proxy directly to the appropriate server/port, and NGINX will hide it from the outside world. Additionally, since the URLs will all refer to the same domain, you can seemlessly integrate a PHP-based blog, Python based tracking system, and Rails app -- as long as you write your URLs correctly.

提交回复
热议问题