Nginx | Reverse proxy - nginx

I have a Nextjs application running on https://localhost port 3000 on my server and it is accessable through https://rgb.irpsc.com:3000/citizen/hm-2000001. The hm-2000001 part is dynamic and can range from hm-2000000 to any value.
What I want to do is to make this application accessable without specifying a port. What I mean is that when a user types https://rgb.irpsc.com/citizen/hm-2000003 in the browser address bar, the related page shows up.
I have configured this in nginx, but it seems to be not working. I'd be so grateful for any help from you guys.
Here's my nginx configuration:
location /citizen {
proxy_pass https://localhost:3000/citizen;
}

You should change your config as below:
location /citizen {
proxy_pass http://localhost:3000;
}

Related

Setting up Jenkins with Nginx reverse proxy

I have a Jenkins environment setup, running off a EC2 instance and trying to get port 80 mapped to port 8080.
A suggestion made (and the way most of the configurations I've seen recommended) uses Nginx to do a reverse proxy.
I have installed Nginx on the server, and added to sites-available the following:
server {
listen 80;
server_name jenkins.acue.io;
location / {
include /etc/nginx/proxy_params;
proxy_pass http://localhost:8080;
proxy_read_timeout 60s;
# Fix the "It appears that your reverse proxy set up is broken" error.
# Make sure the domain name is correct
proxy_redirect http://localhost:8080 https://jenkins.acue.io;
}
}
I hit the IP address of the jenkins environment, it shows me the Ngnix welcome screen and Jenkins still loads against port 8080 not port 80.
Do I need to specific the current URL (I've not pointed the jenkins.acue.io sub-domain yet to the EC2 instance where I have specified localhost? I've tried it but no joy).
Few things to note.
You need to add jenkins.acue.io to your Host entries and point it to the instance where you are running NginX. Then use the FQDN to access Jenkins. Also there is a typo in your proxy_redirect where you have added https URL instead of http://jenkins.acue.io fix that as well. Other than that your NginX configurations look fine.
If you keep on getting the NginX welcome page even though you are accessing through the FQDN, that means your configurations are not being picked up by NginX. Try creating a new file like jenkins.conf and add it to /etc/nginx/conf.d. Then do a sudo systemctl restart nginx

nginx reverse to all pages

I have the following configuration that works for only 1 page:
location /mypage.html/ {
proxy_pass http://${remote_server}/;
}
When I am trying to navigate to other pages on the remote server, I get page not found.
Is there any way to keep the reverse proxy open for all pages on the remote server?
This will match everything, technically everything that starts /, and route the same request to your remote server:
location / {
proxy_pass http://${remote_server}/;
}

Redirect me to :[port]/[whatever I type]

I have an app running on localhost:8080 , I configured Nginix to make it run on localhost/
And I have another app running on localhost:3000
What I want to do is to redirect me to localhost:3000/[whatever] when I originally go to localhost/[whatever]
I wanna do something similar to this:
location /[SOMETHING] {
proxy_pass http://localhost:3000/[THAT_SAME_THING_ABOVE];
}
Is it possible to configure Nginx to do this behavior? if so how?
Thanks
PS: The app running on :8080 is a single page so :8080/[whatever] doesn't even exist now
This is the solution, just in case somebody needs it
location = / {
proxy_pass http://localhost:8080
}
location / {
proxy_pass http://localhost:3000
}

Nginx Proxy for PlayFramework from port to path prefix

I have a Play application listening on a local port :9000. There are other applications running.
I would like to server this application at a path like:
http://myhost/this-play-app -> localhost:9000
So that other apps could be nested at other paths.
I've tried the basic proxy_pass but it doesn't seem to work.
server {
listen 80;
server_name myhost;
# MMC Tool
# ----------------------------------------------------
location /this-play-app {
proxy_pass http://localhost:9000;
}
}
The play app seems to forward to the root. Is there a way to trick the play app to work within the /this-play-app path ?
Like /this-play-app/some-controller instead of /some-controller ?
Thanks
Using apps in folders isn't comfortable idea - you would need to at least prepare some dedicated config and change it each time when changing the location.
Instead as other suggested you should use subdomains, in this case each app behaves exactly the same as in the root domain and even if you will need/want to change that domain all you'll need will be change in the nginx's config.
Typical nginx's config looks like
upstream your_app {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name your-app.domain.com;
location / {
proxy_pass http://your_app;
}
}
Most probably on some VPS or shared hosts you'll need to add the subdomain by some kind of admin's panel - on localhost just need add the subdomain to the hosts file.
Edit if using subdomain is not possible anyway (pity) you can workaround it anyway by config, in nginx use (as you did in question:
...
location /this-play-app {
proxy_pass http://your_app;
}
...
and then add this line into your application.conf (Play 2.1+)
application.context = "/this-play-app"
Or this in case of Play 2.4+ (info)
play.http.context = "/this-play-app"

Deployement of Play! web app with Nginx

I'm trying to do some deploy on my webb app project with Play! and Nginx.
I followed the guide on Play! web site but it dosen't work. Sombody get to make it works?
Wich are the differences?
PS: My web app work, if I it localhost:9000 I get the page and if I hit only localhost I get the welcome message from Nginx, but I can't make them work together.
Thanks
The problem is that you have changed the default port to 9000. Only using localhost/projectname is going through port 80. In order to do it that way you should change your default port to port 80.
I'd say you only need to do a proxy pass in nginx, replace the example.com with your website name.
server {
server_name example.com;
proxy_pass http://localhost:9000;
}
if you don't want to create a separate server block, you can use a location block
location /webapp {
proxy_pass http://localhost:9000;
}
This way it would work by using http://localhost/webapp
Here is my nginx configuration:
upstream play_app {
server 0.0.0.0:9000;
}
server {
listen 7000;
location / {
proxy_pass http://play_app;
}
}
And then you just need to visit your website via: IP:7000

Resources