3

I hace two servers: A running a Nodejs web application and server B running a PHP web application. I want to configure Nginx in such a way that when I type http://www.example.com it routes to the nodejs web application then if I type http://www.example.com/otherinternalpage it routes to the PHP web application.

Server A and B are both in the same intranet and I have installed Nginx in server A.

I apreciate any kind of help. Thanks

1 Answer 1

1

It is possible, but I would suggest to use different sub-domains and a ngnix config file for each application, like I did for my own project :

  • www.leave-management-system.org
  • demo.leave-management-system.org
  • influxdb.leave-management-system.org
  • etc.

The advantage is that you can disable one application without impacting the others and that the configuration is easier to maintain when it comes in different files.

Anyway, you need to (follow the links):

However, if you don't want to use sub-domains, but two different folder on the same domain, a combined configuration could look like this one :

server { 
    listen 80 default;
    server_name www.example.com;
    ...

    location /otherinternalpage/  {
        try_files $uri $uri/ /index.php?/$request_uri;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        #This is a Linux socket config
        #fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
        #Alternatively, you can configure nginx/PHP with a backend
        fastcgi_pass 127.0.0.1:{YOUR_PORT};
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME
            $document_root$fastcgi_script_name;
                fastcgi_buffer_size 128k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
    }

    location / {
        proxy_pass http://localhost:{YOUR_PORT};
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your answering, the php server is hosted in another location inside the same private network, so I got a URL to get the files. It's named organization.example.com so requests comming from users to example.com/otherinternalpage should be redirected to organization.example.com and when the response comes back I still want the users'URL to have example.com/otherinternalpage/PAGE_REQUESTED. Is it possible to have this configuration? thanks again!
I edited my answer. Some changes need to be done so as to fit your needs. You didn't explain the way your PHP application works so you may need to change the location section, see nginx.com/resources/admin-guide/reverse-proxy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.