How to do the request dispatch to jetty in nginx - 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;
}

Related

Wildfly request.getRemoteUser() returns null when accessed through nginx basic authentication

I have Wildfly 24 behind a nginx webserver, acting as a reverse proxy with Basic Authentication. When I access my services with Insomnia I can send a POST (and that works) but the problem is that request.getRemoteUser() returns NULL, instead of the authenticated user from Basic Authentication, and I need that value in my application.
This is my nginx configuration
location / {
auth_basic "Application auth";
auth_basic_user_file /etc/nginx/htpasswd;
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://wildfly/;
include snippets/services.conf;
return 404;
}
where snippets/services.conf contains just a lot of rewrites for legacy reasons.
I have experimented with adding proxy_set_header Authorization $http_authorization; and proxy_pass_header Authorization; but that has so far not yielded any results. Any ideas what I am missing?
It is possible to add a request logger to Wildfly and thus log requests with headers directly into server.log.
Create a custom filter for Undertow, using the RequestDumpingHandler
Add this filter to the default server
Start the CLI (bin/jboss-cli.sh -c) and enter the following commands
/subsystem=undertow/configuration=filter/custom-filter=request-logger:add(module=io.undertow.core, class-name=io.undertow.server.handlers.RequestDumpingHandler)
/subsystem=undertow/server=default-server/host=default-host/filter-ref=request-logger:add()
reload
Remove the logger with these commands:
/subsystem=undertow/server=default-server/host=default-host/filter-ref=request-logger:remove
/subsystem=undertow/configuration=filter/custom-filter=request-logger:remove
reload

How to deploy Flask project on Plesk subdomain

I want to ask if there is a way to deploy my Flask project to a Plesk subdomain. The site is going to be created with wordpress inside Plesk. Also, i would like to have database support.
I was struggeling with a similar issue. What i did was the following:
Installed nginx
In the subdomain -> Apache & nginx Settings, make sure to disable the proxy-mode under the nginx settings
add the following to Additional nginx directives:
location / {
# Define the location of the proxy server to send the request to
proxy_pass http://127.0.0.1:5000;
# Redefine the header fields that NGINX sends to the upstream server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Define the maximum file size on file uploads
client_max_body_size 5M;
}
location /static/ {
alias /var/www/vhosts/PATH/TO/FLASK/app/static/;
}
The rest is handled by gunicorn, you can find a great tutorial here: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux
hope that helps

Nginx reverse proxy root URI issue

I have an application running in Kubernetes with the following topology:
Some-ingress-controller--> nginx reverse proxy -->dynamically generated services.
I have set the NGINX reverse proxy with the following test configuration
location /mysite1/ {
proxy_set_header Host $host;
proxy_set_header Referer $http_referer;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $remote_addr;
proxy_pass http://myservice1.default.svc:9000/;
}
So far everything works fine - when I go to my website http://example.com/mysite1/ I see what I expect from the myservice1 application hosted at http://myservice1.default.svc:9000/. However, the application myservice1 issues requests to various internal (internal meaning they are part of the same container) resources on /get_resourceX. When the myservice1 application tries to access these resources they will be accessed at http://example.com/get_resourceX/ and not at http://example.com/mysite1/get_resourceX as they should - and that is my problem.
What could work is to simply reverse proxy all the relevant resource names as well. However, then I would need to do the same for http://example.com/mysite2, http://example.com/mysite3 etc. which is impractical since these are generated dynamically.
Another possible solution is to check the http Referrer header and see whether it originates from mysite1 - but that seems awfully hackish.
How can I easily have myservice1 requests issued to /get_resourceX served by itself? Is there a generic way to set the root path for the myservice1 application to myservice1?

Nginx proxy with Google OAuth 2.0

I have an Ubuntu 14.04 server and I have a meteor application that runs at localhost:3000 on this server. The public FQDN of my server is sub.example.com. The meteor application uses Google OAuth 2.0, I have the following configured in the Google API Console:
URI REDIRECTION
http://sub.example.com/_oauth/google
http://sub.example.com/_oauth/google?close
ORIGINES JAVASCRIPT
http://sub.example.com
My Nginx config file looks like this:
server {
listen 80 default_server;
server_name sub.example.com www.sub.example.com;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3000;
}
}
The proxy works and I can access my meteor application when I go to sub.example.com. But when in this application I try to use Google OAuth 2.0, a pop up opens as it should and I get :
Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/_oauth/google?close did not match a registered redirect URI.
I have played with the header in the nginx config file with no luck.
I'm obviously missing something.
You should rewrite the Location headers that your backend sends to Nginx described in http://wiki.nginx.org/HttpProxyModule#proxy_redirect, so:
proxy_redirect http://localhost:3000/_oauth/google http://sub.example.com/_oauth/google;
the other option, that would work for popup-style login as well is to set the ROOT_URL environment variable for Meteor at startup as follows:
ROOT_URL="http://sub.example.com" PORT=3000 node main.js

nginx location with proxy server

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.

Resources