Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have an Ubuntu VPC. I have a nodejs app running on it in some folder. I have a php app running on apache in var/www. What I want is to configure nginx so that when a user comes on mydomain.com , he/she is redirected to my node app running on port 3000 and when the user visits mydomain.com/docs , he/she is redirected to my php app running on apache on port 80.

server {
  listen 80;  
  root /var/www;

  location / {
    try_files $uri $uri/ /index.html;

  location ~\.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;

  location /doc/ {
    alias /usr/share/doc/;
    autoindex on;
    deny all;

  location ~/\.ht {
    deny all;

My conf file for nodejs app is:

upstream app_somedomain {

server {
  server_name mydomain.com mydomain;
  root /some/path;
  index index.html index.htm index.php index.js;

  location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://app_somedomain/;
    proxy_redirect off;

I am using nginx for the first time. I am still unable to understand how to achieve this. As in how to serve my nodejs app running on port 3000 to my domain name and mydomain/docs to my php app.


share|improve this question

1 Answer 1

It's not possible to host your php app on url "docs" and nodejs on the main. You can do it like live.domain.com for your nodejs app and specify the server to listen at port 80 with an upstream of port 3000. and then www.domain.com for your php app.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.