Angry Beaver
Angry Beaver

Reputation: 465

Node.js app and Apache php back-end at the same server

I have a VPS which runs under CentOS 7. The idea is: to have under maindomain.com node.js front-end app deployed while under api.maindomain.com to have php back-end deployed. Is it possible? Say, add server blocks to Nginx: reverse proxy localhost:4000 for node.js app and the other block for localhost:80 for php back-end.

Maybe there exists the other solution, I don't know, I would appreciate any ideas! The main goal: to have both app at the same server.

Upvotes: 0

Views: 471

Answers (1)

J-Jacques M
J-Jacques M

Reputation: 1118

Solution 1 with www.maindomain.com + api.maindomain.com

Frontend

server {
    listen 80;
    server_name www.maindomain.com;

    location / {
        root /path/to/your/files;
        try_files  /index.html;
    }
}

Backend php API

server {
    listen 80;
    server_name api.maindomain.com;

    location / {
        proxy_pass http://localhost:4000;
    }

}

Solution 2 everything on same domain, www.maindomain.com

server {
    listen 80;
    server_name www.maindomain.com;

    location /api {
        proxy_pass http://localhost:4000/api;
    }

    location / { # always at the end, like wildcard
        root /path/to/your/files;
        try_files  /index.html;
    }
}

Upvotes: 3

Related Questions