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 it is routed to the nodejs web app then if I type 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


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:

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

    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_index index.php;
        fastcgi_param SCRIPT_FILENAME
                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;




All Articles