Deployement of Play! web app with Nginx - 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

Related

Nginx | Reverse proxy

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;
}

Download files in remote server using reverse proxy Nginx

I have a server running with Nginx reverse proxy.
We have our application running in another server, which is served using this Nginx proxy. Below is the configuration I have used and its working fine.
location / {
rewrite ^/(.*) /$1 break;
proxy_pass http://10.0.0.121:8000;
}
I would need to download a pdf file in the application machine (10.0.0.121) , which is under /home/ubuntu/app/pdf/data-2021-03-25.pdf.
How could I make the file in application machine downloadable from the proxy server, please help.
Thanks in Advance.
I would simply install another nginx instance on 10.0.0.121 and configure it like this. NON-PROD READY!
server {
listen 8080;
server_name ...;
root /home/ubuntu/app/pdf;
location = /data-2021-03-25.pdf {
try_files $uri $uri/ =404;
}
server {
listen 8090;
location / {
proxy_pass http://localhost:8080;
}
}
}
Not tested but this server will handling the request serving the file. Then you could just use proxy_pass on the other server to proxy the request.
But beside from this option you can use a python, perl, php, java, nodejs, assembly or what ever programming language you want to use to open a http port and serve the file on an incoming request. Its really your choice.
just make sure if you're going for the proxy solution you are sanitizing the requests on your proxy. For example. With a small change in the setup above you could cheat and get any other files from your home/app directory by sending an request like curl -v localhost:8090/pdf/../other/file. So make sure you are using the root(/home/ubuntu/app/pdf/) directive and set a location matching the pdf-file on the proxy-server as well.
That worked in my demo app.

Nginx: link to another server on a different port

I have an Nginx server/site installed on my Raspberry pi and runs on https://example.com.
I also have a Calibre ebook server on the same Raspberry pi that runs on https://example.com:8585. Having a port number at the end is ugly and not easy to remember.
I want my Calibre server to be accessible at https://example.com/calibre
Is there a setting in the Nginx server that I can tweak to achieve this? I am new to web server setups. Any suggestions would be helpful. Thanks!
Two simple ways. First - create location /calibre which cuts "/calibre" and pass requests to 8585 (trailng slash at end of proxy_pass is important)
server {
...
location /calibre {
proxy_pass https://example.com:8585/;
}
...
}
Second (and better I think) way - to create subdomain calibre.example.com in your DNS and make another server{} for calibre like this
server {
listen 443 ssl;
... ssl options here...
server_name calibre.example.com;
location / {
proxy_pass https://example.com:8585;
}
}

Some sites can not be proxied? How ist this behaviour achieved?

I was having trouble configuring an nginx reverse proxy within my development environment when I stumbled on a behaviour that I do not quite get.
So nginx is listening on port 8080. When I make a request to my development-server, I can access my development server on
localhost:8080
With the following directives:
server {
listen 8080;
server_name site.com;
location / {
proxy_pass http://localhost:3000/;
proxy_redirect off;
}
But when I put a known website in the proxy pass_directive like google or apple the behaviour is different. I can not access e. g. apple.com as localhost:8080 with the following directives - I am immediately pushed to the real website and not the localhost:
server {
listen 8080;
server_name site.com;
location / {
proxy_pass http://apple.com/;
proxy_redirect off;
}
How is that behaviour called and how is it achieved? Can you guys put me in the right direction to understanding this? Thanks.
This is the correct behavior for the proxy service, you can find docs here https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
Some information regarding proxies here https://en.wikipedia.org/wiki/Proxy_server
Example: if you want to go to http://apple.com/apple-card/, you can point out to localhost:8080/apple-card and you will be redirected to /requested_path
I'm using proxies with docker containers just to route the requests to the correct application using different ports.

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"

Resources