I am setting up nginx for a website and I want it to route to 3 locations - the main frontend server, api server and to the wordpress blog server. I can get it working for the frontend server and wordpress, but the upstream api server is always giving 404 when accessing the API's via the frontend. The wordpress is running on port 8080
, while the 2 NodeJS servers are running on 8015
& 8016
. While hitting mysite.com
frontend server on 8015
shows up the UI, but on calling the login API on port 8016
it throws 404 error. mysite.com/blog
shows up the Worpress Blog after rewriting the url to mysite.com:8080
The nginx config is given:
upstream backend {
server <IP>:8016
}
server {
listen 80;
server_name mysite.com;
location / {
root /code/public;
index index.html
try_files $uri $uri/ /index.html;
}
location /api/{
proxy_set_header Host $http_host;
proxy_pass http://backend/;
}
location /blog {
root /var/www/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php;
}
location ~\.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://<IP>:8080;
}
location~/\.ht {
deny all;
}
}
What could be wrong here?