Maybe this question got already answered but I can't find the solution for my problem resp. no solution worked for me.
I'm pretty new with NGINX and I've now set up a Raspberry Pi 2 Model B as a Reverse Proxy with NGINX in our company-network. RPi OS is Raspbian v7.
The Hostname (raspberry) of this Reverse Proxy is set over our DHCP Server with a reserved IP.
At the moment I'm able to access another internal Server (resp. its webpage) when I enter the URL for my raspberry in my webbrowser - this works fine.
nginx.conf configuration - working server block in http block:
server {
listen 80 default_server;
server_name webpage;
location / {
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_pass <link for mentioned webpage>;
}
}
Now I would like to be able to access other public/internal websites by entering URLs like:
raspberry/stackoverflow (proxies to stackoverflow)
raspberry/google (proxies to google)
raspberry/facebook (proxies to facebook)
in my webbrowser.
I've tried to use different location blocks in nginx.conf like:
server {
listen 80 default_server;
location /webpage {
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_pass <link for mentioned webpage>;
}
location /stackoverflow {
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_pass <link-stackoverflow>;
}
location /google{
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_pass <link-google>;
}
#and so on.....
}
But this doesn't work, if I enter raspberry/google I get a 404 error from google:
The requested URL /google was not found on this server
This means it searches for https://www.google.com/google instead of just https://www.google.com/
How could I realise my plan? Any help is greatly appreciated :)
P.S. Stackoverflow doesn't allow me to post more than 2 links yet so I wasn't able to write real links (see <>).
Related
I'm running an Express server on port 5000 and a React app on 8080.
My idea was to just direct traffic based on location (uri), but I've been getting a duplicate location "/" error with this partial insert into the AWS Beanstalk ngnix config:
location / {
root /var/app/current/build/;
try_files $uri /index.html;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /socket-io {
proxy_pass http://127.0.0.1:5000/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;
proxy_ssl_session_reuse off;
proxy_cache_bypass $http_upgrade;
}
This gets included in a standard ngnix.conf which looks roughly like this: https://gist.github.com/alextanhongpin/00da7f551969f052e57f3c4dcd9ac4b0
This is some combination of this answer and this other one since AWS documentation keeps changing.
On EC2, the file /etc/nginx/conf.d/elasticbeanstalk/00_application.conf is the file that appears to get appended on the main nginx.conf file with the line /etc/nginx/nginx.conf.
HOWEVER
The latest documentation says having .platform/nginx/conf.d/your_custom.conf in your working directory is the real nginx extension file.
I had to manually change 00_application.conf on EC2 in order for the duplicate error to go away, it appears this file stayed default even when redeploying with the custom config files, and that file happens to have a location / {}.
So I would recommend the container_command method or manually changing it for now.
I have a laravel website, where on my website there is a feature to get IP address for clients that open my website.
But when I use nginx for reverse proxy, on my website what is read is the Nginx server IP, not the client IP.
I already added :
proxy_set_header Host $ host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
And this my nginx configuration :
upstream my.site {
server 192.168.1.5:30111;
server 192.168.1.4:30111;
server 192.168.1.3:30111 backup;
server 192.168.1.2:30111 backup;
}
server {
server_name my.site;
location / {
proxy_pass http://my.site;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
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;
}
Still not working.
Please help me.
i have a laravel app and i want all requests to domain.test/api to be proxied to nodeJs but only if it is an xhr request. meaning that if a user types in a browser domain.test/api i want to give him a 404 but if the request is made with ajax i want to give him the response.
the following configuration proxies all:
location ~* ^\/api(.*)$ {
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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;
proxy_read_timeout 300;
proxy_pass http://localhost:8081;
}
Is what i want to do possible using nginx? if so, please do suggest your solutions?
it's very short question, but i'm overwhelmed. I need nodejs app run under domain.com/nodeapp/.
The problem is - it works correct if i write domain name like: domain.name/nodeapp/ so when i'm go to domain.name/nodeapp - corrupted version loads.
I need nginx to redirect correctly to location with /nodeapp/
Now i'm using next config:
location /nodeapp {
proxy_pass http://localhost:20100;
rewrite ^/nodeapp/?(.*)$ /$1 break;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
How can i do it correct? Thanks!
This will do
location /nodeapp {
proxy_pass http://localhost:20100;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
To remove the use of ports on several of the applications running on this server, I've been using nginx's proxy_pass to do this. However, for some reason the actual url is being passed to the application. Is there a way so that it thinks /panel is really just /?
location /panel {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8082/;
}
You need to add the trailing slash
location /panel/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8082/;
}