Port redirection for domain - nginx

I have NGINX on my VPS working on port 80 (few domains on it), and I want add GlassFish on port 8080.
Next I want add domain for GlassFish, but on domain it should work on port 80.
How I can do that?

Him add server rule, for example:
server {
listen 80;
server_name demo.glass.fish;
location / {
proxy_pass http://localhost:8080;
}
}

Related

Using NGINX as a load balancer for a API

My goal is to have NGINX act as a load balancer for an API that is on different ports on my local computer. The issue is the API I am using needs to point to a specific location on the server in order to work. In the example below I am using NGINX only as a reverse proxy.
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080/api/darkshield/searchContext.mask;
}
I have a python script that acts as the user and it works no problem. The issue is when I try to create an upstream to have NGINX act as the load balancer for the API.
upstream backend{
server localhost:8080;
server localhost:8081;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://backend/;
}
In the upstream when I create the group of servers I can't add the "/api/darkshield/searchContext.mask" to the end of the port number like I could in the first example because NGINX won't run. From what I've seen I can only use an IP and Port Number. Is there a way to add the missing information once a server has been picked from the upstream?

Nginx proxy_pass rule Issue

So, I'm running some docker containers serving on ports 8090 and 8000. Now I want to setup Nginx reverse proxy to handle requests to both of these ports internally. The main URL http://milesblock.com changes automatically to http://milesblock.com/#/
I have setup a proxy_pass in nginx as follows-
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name milesblock.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:8090;
}
location /api {
rewrite ^/api(.*) $1 break;
proxy_pass http://127.0.0.1:8000;
}
}
Now, the issue is because of the automatic change of the URL to http://milesblock.com/#/ the redirect to both the ports is not working as intended. Only the /api proxy is working with the above config file.
How do i configure the proxy to handle the traffic on port 8090 and also the api calls on port 8000?

Trouble setting up NGINX behind pfSense Router

I'm attempting to setup an NGINX reverse proxy on my network, it is currently running on an Ubuntu VM. I'd like to run a website running in IIS, and another site running on Apache in a Linux VM behind the same public IP address. NGINX seemed like the perfect solution.
I've followed several guides and can't seem to get everything working. The NGINX config seems to work locally if I access the NGINX VM's IP directly it serves me the default config, and I can even change it between the IIS site, or the Apache site, and get it to work locally. My problem comes in with any external connection.
Previously my pfSense router was setup to forward port 80 and 443 to the IIS VM, and that was working fine, so I know at a basic level that pfSense was able to forward those ports to that windows client. Once I got NGINX setup I changed my port forwards for 80 and 443 to point to the VM running NGINX. Now none of my websites will work, the ip address for the domains resolves to my public IP, but the requests time out / never reach any web server.
nginx.conf is the default, I made no changes.
default nginx host conf:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
return 404;
}
}
Apache host conf:
server {
listen 80;
server_name domain.com;
location / {
proxy_pass http://0.0.0.0:80; # Apache internal IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
pfSense Port 80 Rule:
Action: Pass
Interface: WAN
Address Family: IPv4
Protocol: TCP
Source: Any
Destination: NGINX VM IP
From: 80
To: 80
I'm not getting any error messages in the console, in the NGINX log, etc. I'm honestly at a loss. Any advice would be greatly appreciated.
You have it set up so Apache is forwarding to Nginx. Your Nginx file is not forwarding anything. If Nginxis going to be the reverse proxy, then the location / { ... } components showing in the Apache config file need to be in the Nginx config file. Also, I would change "server name _" to show your domain name in the Nginx file.

Nginx win server 2012 - Configure proxy pass

I have a node server listening on localhost:8080 and I'd like to use nginx as proxy pass, so i made nginx listen to port 80 incoming connections. However I'm not able to configure nginx config to do the reverse proxying. I do not currently have a domain, only server IP. So I'm guessing server_name has to be set to $host or something?
events{
}
http{
server{
listen 80;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host 127.0.0.1;
}
}
}
If I try to visit my server IP on port 80 I just receive welcome to Nginx page.
You should reload and restart your nginx
sudo service nginx reload
sudo service nginx restart

To test Nginx load-balancing in local system

I wanted to test if nginx is redirecting to node-2 if node-1 is down.
For that, I installed tomcat in my local windows machine and started 2 instances in 8080 and 9090 port
Dont know how to configure nginx for this. I tested by adding below blocks in nginx.conf . But still it is not working for me. Please help me on this
proxy_redirect ~.*:909[0-9]/(.*)$ /$1;
proxy_redirect ~.*:808[0-9]/(.*)$ /$1;
upstream localhost {
server localhost:8080;
server localhost:9090;
}
server {
listen 8080;
server_name localhost;
}
Replace the server block by below block
server {
listen 8080;
location / {
proxy_pass http://localhost;
}
}

Resources