nginx location with proxy server - nginx

Got nginx proxy server setup ready. The server handles requests from main machine.
The following configuration is working for common files, but flv returns 404 not found error:
location / {
proxy_pass http://x.x.x.x:80/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Remote-Addr $remote_addr;
location ~* \.flv$ {
flv;
root /var/www/machinery/data/www;
}
}
Basically i want .flv pseudo-streaming handled by the server. It seems nginx is trying to find a flv file inside the proxy server(according to logs), not in the main server where file is located.
How do I do it?

The question would actually be: Can someone use NGinx to do pseudo streaming for proxied FLV files?
And the answer is no, you cannot.

Related

How to Recycle NGINX Processes when proxy_pass timeout occurs?

Inside of my nginx config file, I have several endpoints that use proxy pass to another server which hosts static files. My current settings within the individual site config file is as follow:
location /some_location {
proxy_pass http://some.website.url/version/;
proxy_http_version 1.1;
proxy_set_header "Connection" "";
}
I have the following as proxy parameters
proxy_set_header Host $http_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;
What happens is if a request times out for some reason, all future attempts to reach those files results in a 504 Gateway Timeout. Even if the individual files can now be accessed because the issues on the destination server is resolved, I need to restart/reload nginx on the originating server for the requests to work properly.
Is there a way to recycle or reset the connections so that it will be smart and retry the connection after a timeout?
Thanks!
The issue was that the website url's ip address was changing and the way that I was doing it was only resolving the dns on initial startup.
Here is what we did to fix it per this post:
location ~ ^/some_location(/?)(.*)$ {
resolver "aws_vpc_dns_resolver_ip" valid=10s;
set $backend "some.website.url";
proxy_pass http://$backend/version/$2;
proxy_http_version 1.1;
proxy_set_header "Connection" "";
}

Bitbucket over http nginx proxy

I have a bitbucket server that works on a direct IP address very well. But I want to access my bitbucket server using subdomain name and over HTTP, something like bitbucket.subdomain.com
I have found a very good official Atlassian's explanation on how to do it and started from adding new server parameters to the bitbucket.properties
server.port=7990
server.secure=true
server.scheme=http
server.proxy-port=80
server.proxy-name=bitbucket.mydomain.com
server.context-path=/
everything looks clear to me, so I've decided to change my Nginx configuration and added next server settings
#Bitbucket
server {
server_name bitbucket.mydomain.com;
# serve static files directly
#location for bitbucket
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:7990;
}
}
the same looks cool for me.
Did all restarts/reload etc and going in my browser to bitbucket.subdomain.com and I see 404
So, I'm really stuck, since I've done a lot of different changes and no, it's not working
Can anyone help?
I try the same stuff and this works for me:
Bitbucket.properties:
server.port=7990
server.scheme=http
server.proxy-port=80
server.proxy-name=bitbucket.mydomain.com
Nginx
server {
listen 80;
server_name bitbucket.mydomain.com;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:7990/;
client_max_body_size 10M;
}
}
Then restart both and you are ready to go.
V.

Executing Liferay behing a Nginx reverse proxy

I am trying to test the last version of Liferay (Liferay 7.0-ga4) and install it behind a reverse proxy (nginx). I am using docker and docker compose for testing purposes, and I create a dummy domain docker.domain.com.
Liferay works fine if I access directly to its url and no reverse proxy is configured.
Also, I have success to install Liferay behind the nginx server if I use the root location:
location / {
proxy_pass http://liferay:8080;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
Where liferay in the proxy_pass section is the name of the docker container linked in the docker compose. And Liferay's options:
web.server.host=docker.domain.com
web.server.protocol=http
web.server.http.port=80
To configure the reverse proxy in Liferay. The results is correct if I type http://docker.domain.com/:
I can login, accept terms and conditions, ... everything seems fine.
But when I use a location that is not root (i.e /lifeay), I have issues with links, images, and css in general.
With a configuraion in nginx similar to:
location /liferay {
proxy_pass http://liferay:8080;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
And adding as suggested here to Liferay's configuration:
portal.proxy.path=/liferay
When accessing to http://docker.domain.com/liferay all url are messed up and CSS are not shown. Here I attach an screenshot of the final result:
It is interesting the line
http://docker.domain.com/liferay/liferay
Where "liferay" appears two times in the url. Some errors appear at the liferay's tomcat log:
12:48:29,019 WARN [http-nio-8080-exec-3][code_jsp:172] {code="404", msg="/liferay/o/mentions-web/css/mentions.css", uri=/liferay/o/mentions-web/css/mentions.css}
12:48:29,021 WARN [http-nio-8080-exec-8][code_jsp:172] {code="404", msg="/liferay/o/frontend-css-web/main.css", uri=/liferay/o/frontend-css-web/main.css}
....
Obviously some files are not found. I have created a simple example with docker github to test it only spending a few minutes if somebody is interested. Still, I am pretty sure that something is missing in my Liferay configuration, but I am not able to figure out what. At least I am not able to find any clue in the official documentation.
Seems that the problem was with the the trailing slash in proxy_pass. It is what makes a difference. Following this example, the nginx configuration file will be:
location /liferay {
return 302 /liferay/;
}
location /liferay/ {
proxy_pass http://liferay:8080/;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
And now seems that Liferay CSS and URLs are correctly working.

Can NGINX work as Webserver and Proxy Server At Same Time?

We have a situation where we need to serve the login page from server_A (NGINX), get the user authenticated from here and once authenticated route the request ta a page which resides in a different server i.e. Server_B. All subsequent requests will come to Server_A and it will first check the user and session validity and then route to Server_B. This way the session and security is maintained by server A and rest of the work is done by server B.
My question here is that can we acheive this from NGINX server ?
My question here is that can we acheive this from NGINX server ?
Yes, certainly.
How do you do that?
Taking for an example a modified Tomcat behind NGINX application config I have handy:
server {
listen 80;
server_name www.example.com;
location /{
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://servera.example.com:8080/app;
client_max_body_size 10M;
}
location /login{
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://serverb.example.com:8080/login;
client_max_body_size 10M;
}
}
This will both proxy requests to the TomCat server, and serve them like any HTTP server.
Same can be said for any application you may want to proxy to, just modify the proxy_pass line of the above config accordingly!

How to do the request dispatch to jetty in nginx

I use nginx for my front web server to serve the static files like .js .css and .html.
However in my page,I have to use the ajax request.
So I tried to create the web service in java and deploy it use jetty.
Now my main application is ran under nginx:
location /mainapp{
alias /cygdrive/D/workspace/mainapp/;
autoindex on;
}
http://localhost/mainapp
Now in my page I have to do some ajax requst like :
http://localhost/mainapp/webservice.do/xxx
http://localhost/mainapp/utilservice.do/xxx
I have implement these services using java, and deploy them using jetty which can be accessed using:
http://localhost:8080/backup/webservice/xxx
http://localhost:8080/backup/utilservice/xxx
How to make the nginx dispatch the request to jetty?
Edit the configure file of nginx as following
vi /usr/local/etc/nginx/nginx.conf
location ~ \.(jsp|jspx|do)?$ {
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_pass http://127.0.0.1:8080;
}

Resources