env['REMOTE_ADDR'] with Goliath ruby - 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']

Related

Simple Nginx proxy pass not working with Laravel Valet installed

Quick backstory, I used Laravel Valet to setup a local development environment. I've since containerized the application and would like to just have Nginx proxy the main port 80 traffic to the localhost:8000 port the docker container is listening at. I've tried to remove (unpark/stop) Valet. I've commented out the lines from the nginx.conf that refer to the Valet config files. Nothing seems to work though
Here is my conf:
server {
listen 80;
server_name app.trucase.test paylaw.trucase.test;
location / {
proxy_pass http://127.0.0.0:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
I can go to app.trucase.test:8000 and it all works. But without the port, Nginx just isn't proxying the traffic. What am I missing?

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

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

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.

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

How can configure the Magento 2 With Varnish Cache with HTTPS

Thank you for looking on this.
I have a Magento 2.1.8 website and it will run on the Amazon EC2 with this https://aws.amazon.com/marketplace/pp/B007OUYR4Y Amazon AMI.
I have optimized everything on Magento 2 website but did not get the proper result on this.
I have tried to use the Varnish cache but it is not working with the HTTPS.
anyone have an idea, how can use the varnish with the HTTPS to optimize the website speed.
Varnish Cache does dot speak HTTPS natively. You'll need an SSL terminator such as Hitch, HAProxy, etc. deployed in front of Varnish, ideally using the PROXY protocol.
With my setups I use NGINX as a proxy to handle both http and https requests and then use Varnish as the backend so NGINX handles all the SSL certificates.
Here's an example of my NGINX ssl template:
server {
listen server-ip:443 ssl;
server_name example.com www.example.com;
ssl_certificate /home/user/conf/web/ssl.example.com.pem;
ssl_certificate_key /home/user/conf/web/ssl.example.com.key;
location / {
proxy_pass http://varnish-ip:6081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Nginx on;
proxy_redirect off;
}
location #fallback {
proxy_pass http://varnish-ip:6081;
}
}

Resources