Nginx using NodeJS and Apache

I have two servers running a Nodejs web app and server B with a PHP web app. I want to configure Nginx so that when I enter http://www.example.com it is routed to the nodejs web app then if I type http://www.example.com/otherinternalpage it is redirected to the web app PHP.

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

Any help is welcome. Thanks to

+3


source to share


1 answer


Perhaps, but I would suggest using different subdomains and ngnix config file for each application, for example for my own project:

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

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

In any case, you need (from the links):



  • configure nginx as a reverse proxy.
  • Start Nodejs forever .
  • Run PHP as a FastCGI process using PHP FPM .

However, if you don't want to use subdomains, but two different folders in the same domain, the combined configuration might look like this:

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

      

+1


source







All Articles