How to configure tomcat into two different domains in one application? - spring

I wanted to split my applications so that I can configure Tomkat into two different domains "example.com" and "api.example.com". Is it possible to do this with one application? So that some requests are processed on subdomain.

Sure, you can multiple domains of redirecting to multiple Tomcat applications. You would need to install the applications in your Tomcat and make them listen for different ports. Then if you were to use Nginx, all you have to do is change the server clause in your /sites-enabled/ directory from your installation. For your case, you will need two files, one for each domain.
FILE 1
server {
server_name 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://localhost:8080;
}
}
FILE 2
server {
server_name api.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://localhost:8081;
}
}
You can find more information in the following url.

Related

Setting up laravel Project into Nginx Reverse Proxy

I have a problem setting up Laravel Project into my Nginx Reverse Proxy
I had proxy pass my laravel project into nginx reverse-proxy.conf
Here is my configuration in reverse-proxy.conf
location ^~ "/pys/" {
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_set_header Cookie $http_cookie;
proxy_pass http://XXX.XX.X.X:1228/;
}
When I run into my browser, with my url XXX.XXX.X.XX/pys it will redirect to login page,
after entering the credentials, the page returns 404 not found and with the URL of XXX.XXX.X.XX only and all the routes in Laravel Project is affected.
Is there any possibility that I can fix the URL with /pys ?
Thank you

How to remove author filter from SonarQube issue overview

I was asked by my workers council to remove the author and assignee filter from the SonarQube issues page. I'm using SonarQube version 6.7.7 (build 38951).
Currently I don't see any option to configure this. Is there any option to remove the filter? I know that I can disable to analysis of of the SCM commits at all, but I want to keep the my issues feature and the notification on new issue.
Unfortunately, it is impossible by using only SonarQube (check the proposal about the nginx proxy configuration) and won't be implemented. Read more details here: SONAR-11028 Turning off developer nominative information/metrics.
Finally we are now using a workaround that filters certain requests to the SonarQube API with an nginx reverse proxy.
Here is a configuration example:
events {
worker_connections 1024;
}
http {
server {
listen 80;
listen [::]:80;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://sonarqube:9000;
}
location /api/issues/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header Accept-Encoding "";
proxy_pass http://sonarqube:9000;
sub_filter_once off;
sub_filter_types application/json;
sub_filter 'authors' 'XXXXXXXXXX';
sub_filter 'assignees' 'XXXXXXXXXX';
}
}
}

nginx prod setup for Clojure WebSocket app

I'm trying to deploy my first Clojure WebSocket app and I think I'm getting close. I get a good response locally, and it looks like the endpoint wants to face the outside world (I see that the port is open when I run netstat), but no response. I'm certain that I have something setup incorrectly in nginx.
I currently already host a few other websites on this server, just want to add the necessary config to get requests made to wss://domain.com:8001 to communicate with my app.
Here is the location entry I'm using now:
location / {
proxy_pass http://localhost:8001;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
access_log /var/www/logs/test.access.log;
error_log /var/www/logs/test.error.log;
}
Could anyone help point me in the right direction? My guess is that I actually have too much in the config, and what's there is probably not correct.
** EDIT: ** For interested parties, I put up my working config (based on Erik Dannenberg's answer) in a gist.
You are missing two more headers, a minimal working config:
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
# add the two below
proxy_set_header Upgrade websocket;
proxy_set_header Connection upgrade;
# optional, but helpful if you run into timeouts
proxy_read_timeout 86400;
}

Nginx fails to load static after putting caching configuration

I am trying to implement leverage browser caching for my flask project nginx. But when i insert the code inside conf file static files are not served by nginx showing 403 permission denied error.
This is my conf file for site in site-enabled
server {
listen 80;
server_name site.in;
root /root/site-demo/;
access_log /var/log/site/access_log;
error_log /var/log/site/error_log;
location / {
proxy_pass http://127.0.0.1:4000/;
proxy_redirect http://127.0.0.1:4000 http://site.in;
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_set_header X-Forwarded-Proto $scheme;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
}
When i remove the cache expire part everything works fine. I tried similar question's answers and put root specification. But still error remains same. User specified in nginx.conf is www-data. Do i have to change user?

env['REMOTE_ADDR'] with Goliath ruby

I have an API with Goliath gem (ruby) and I want to get the ip of the movile which is calling to my API. The case is, env['REMOTE_ADDR'] always give me 127.0.0.1 when some device is calling me. It shoud be the ip from the mobile is calling me, right?
Any help please?
Thanks in advance!
The problem was with proxying through Nginx. I had to change the Nginx proxy configuration as follows.
upstream app_xxx {
server 127.0.0.1:3000;
}
server {
listen 80;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://app_xxx;
}
}
The important thing is: The real IP is in the X-Real-IP parameter. So you have to access it as:
env['X-Real-IP']

Resources