skip to Main Content

I’m like to config my apache server to run WordPress on the main page and my Rails app on subdirectory. I mean:

mysite.com -> go to WordPress

mysite.com/app -> go to Rails

How can I accomplish this?

2

Answers


  1. <VirtualHost>
        ServerName mysite.com
    
        ProxyPass / https://localhost:8000/
        ProxyPassReverse / https://localhost:8000/
    
    
        ProxyPass /app http://localhost:3000/
        ProxyPassReverse /app http://localhost:3000/
    </VirtualHost>
    

    From Apache:

    In addition to being a “basic” web server, and providing static and dynamic content to end-users, Apache httpd (as well as most other web servers) can also act as a reverse proxy server, also-known-as a “gateway” server.

    In such scenarios, httpd itself does not generate or host the data,
    but rather the content is obtained by one or several backend servers,
    which normally have no direct connection to the external network. As
    httpd receives a request from a client, the request itself is proxied
    to one of these backend servers, which then handles the request,
    generates the content and then sends this content back to httpd, which
    then generates the actual HTTP response back to the client.

    So your backend will be running two separate servers: WordPress and Rails. We just essentially change the relevant port and pass the request through. Then the content is returned to Apache and Apache generates the correct HTTP response.

    Login or Signup to reply.
  2. Read this article for explain. click here
    Two things are needed

    1. change in application.rb file
    module YourAPPName
      class Application < Rails::Application
        config.relative_url_root = '/runthisinrubyonrails'
        # some other configuration code
      end
    end
    
    1. change nginx configuration
    upstream unicorn_sock {
      server your_sock_path;
    }
    
    server {
    root <path_to_your_rails_app>/public;
    location @proxy_rails_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://unicorn_sock;
    }
    location /runthisinrubyonrails/ {
      alias <path_to_your_rails_app>/public/;
      try_files $uri @proxy_rails_app;
    }
    try_files $uri @proxy_rails_app;
     some other configuration code
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search