TLDR: configure nginx to listen on port 80 and use
- if
/api, expressJS onlocalhost:8081 - if
/blog, wordpress/apache2 onlocalhost:8082 - else angular server
localhost:8080angular and express servers working but need to configure wordpress/apache.
In detail, I have installed followings on same VPS:
angularfrontend on port8080expressJSbackend on port8081- WordPress running on
apache2on port 8082
Currently, I'm using nginx to manipulate requests and the config is
server {
listen 443;
ssl on;
ssl_certificate /home/user/.ssh/ssl/ssl.crt;
ssl_certificate_key /home/user/.ssh/ssl/ssl.key.txt;
root /var/www/html;
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8080;
proxy_read_timeout 90;
}
location /api {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8081;
proxy_read_timeout 90;
}
}
Now I need to host my blog on mysite.com/blog. so I added followings to nginx config.
location /blog {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8082;
proxy_read_timeout 90;
}
Now when I go to example.com/blog, it redirects to example.com:8082/blog. How to configure nginx and apache together?
PS: Apache isn't required as long as wordpress works. But I like to keep nginx
PPS: I have configured nginx to forward all http requests to https://example.com/ via redirect 301