I have a problem configuring an nginx as reverse proxy.
On RaspPI with raspberry Lite OS, I installed the pihole reachable under: 192.168.177.77:81
nginx runs on port 80. In the hosts file on a mac notebook, I created the entry:
192.168.177.77 pihole.dummydomain.com
On the RaspPi, I configured NGINX as reverse proxy:
192.168.177.77:80 should redirects to 192.168.177.77:81
NGINX config:
IN /etc/nginx/sites-enabled/pihole.dummydomain.com.conf
server {
listen 80;
server_name pihole.dummydomain.com;
location / {
proxy_pass http://192.168.177.77:81;
proxy_buffering off;
}
}
The redirect does not work. Visting pihole.dummydomain.com shown the nginx default index page instead of the pihole welcome page
Could you please help?
Problem solved. I did a mistake. I had a former nginx installation and I configured the wrong file.
I removed all nginx installations and install a proper one. Now it works as expected
Related
I have a Jenkins environment setup, running off a EC2 instance and trying to get port 80 mapped to port 8080.
A suggestion made (and the way most of the configurations I've seen recommended) uses Nginx to do a reverse proxy.
I have installed Nginx on the server, and added to sites-available the following:
server {
listen 80;
server_name jenkins.acue.io;
location / {
include /etc/nginx/proxy_params;
proxy_pass http://localhost:8080;
proxy_read_timeout 60s;
# Fix the "It appears that your reverse proxy set up is broken" error.
# Make sure the domain name is correct
proxy_redirect http://localhost:8080 https://jenkins.acue.io;
}
}
I hit the IP address of the jenkins environment, it shows me the Ngnix welcome screen and Jenkins still loads against port 8080 not port 80.
Do I need to specific the current URL (I've not pointed the jenkins.acue.io sub-domain yet to the EC2 instance where I have specified localhost? I've tried it but no joy).
Few things to note.
You need to add jenkins.acue.io to your Host entries and point it to the instance where you are running NginX. Then use the FQDN to access Jenkins. Also there is a typo in your proxy_redirect where you have added https URL instead of http://jenkins.acue.io fix that as well. Other than that your NginX configurations look fine.
If you keep on getting the NginX welcome page even though you are accessing through the FQDN, that means your configurations are not being picked up by NginX. Try creating a new file like jenkins.conf and add it to /etc/nginx/conf.d. Then do a sudo systemctl restart nginx
I am a new user of nginx and I am following a video guide from Linode on youtube (How to Set Up an NGINX Reverse Proxy).
I have a working nginx and apache server both on port 80. I know that because when I type the ip address of both in firefox, it directs me to nginx/apache welcome page.
The youtube video configuration template is as follow (where the server_name is the linode ip) :
server {
listen 80;
listen [..]:80;
server_name 172.105.104.226;
location / {
proxy_pass http://localhost:3000/;
}
On my Proxmox machine, the nginx server is on a VM at 192.168.1.241 and the apache server on another VM at 192.168.1.243.
Looking at nginx documentation we find that this :
location /some/path/ {
proxy_pass http://www.example.com/link/;
}
should proxy all the traffic received on the nginx listening port and redirect it to the address specified by proxy pass.
With all these information, my configuration file is like this :
server {
listen 80;
listen [::]:80;
server_name 192.168.1.241;
location / {
proxy_pass http://192.168.1.243;
}
}
My understanding is that this configuration file should listen at the address 192.168.1.241 on port 80 (nginx server) and redirect it to the specified address 192.168.1.243 (apache server)/
If i understand correctly, Location / should take the request as is received on the nginx server and redirect it to the apache server.
However, when I enter 192.168.1.241 in my browser, it doesn't show the apache welcome message but shows the nginx welcome message. That means that the proxy isn't working.
My nginx understanding is extremely limited as I am just starting to learn, but to me it seems like this should work but doesn't.
Thank you for your help
It turns out that the configuration is correct.
The problem was that the webpage was cached. By forcing a full refresh, 192.168.1.241 redirected to 192.168.1.243 successfully.
I've set up nginx to run as in the following :
server{
listen 80;
server_name MYWEBSITE;
.....
}
server{
listen 8000;
server_name MYWEBSITE;
.....
}
Whenever I go to MYWEBSITE, on port 80 the page opens but on my port 8000 it's failing.
What I have tried is reversing server's port so I made sure that both of my web servers are working.
Also I have tried the same setup on a local machine and it's working.
This setup is for my linode server. So I guess it's something related to linode.
Ports are open and this was checked using Nmap.
Where do I need to look for solving the issue ? Any thoughts?
I have a flask app running with gunicorn and nginx on Ubuntu 14.04 using AWS EC2. I have deleted default site from /etc/nginx/sites-available and /etc/nginx/sites-enabled. In those two folders, there is only one file: flasky - my nginx file as below:
server {
listen 80;
location / {
include proxy_params;
proxy_pass http://unix:/tmp/flasky.sock;
}
When I enter the IP of the server in the browser, the default Nginx static page shows up. If I go to /auth/login, the correct page served by Flask shows up properly.
If the change the port from 80 to 8080, restart Nginx, enter http://ip-address:8080 then all Flask pages work well. I don't know how to fix this for port 80. Please help! Thanks!
UPDATE: I just found out that if I use the AWS Public DNS: http://ec2-50-112-125-180.us-west-2.compute.amazonaws.com, it works. But if I use the corresponding Elastic IP: 50.112.125.180 it shows the nginx default page. Anyone knows why?
Search your nginx.conf for the word include
maybe it's including other directories for config files.
Also, there may be other config blocks with
location /
that is superseding this section that also have listen 80.
I want to test nginx subdomains before uploading config to the server. Can i test it on localhost? I try
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
}
}
server {
listen 80;
server_name sub.localhost;
location / {
proxy_pass http://localhost:8080/sub;
}
}
And it does not work. Shoulld i change my hosts file in order to make it work? Also, after uploading site to the server should i change DNS records and add sub.mydomain.com?
Yes, add '127.0.0.1 sub.localhost' to your hosts file. That sub has to be resolved somehow. That should work.
Then once you're ready to go to the net, yes, add an a or cname record for the subdomain sub.
When I use proxy_pass I also include the proxy.conf from nginx.
http://wiki.nginx.org/HttpProxyModule
In Linux based OS just to edit as sudo /etc/hosts file and change 127.0.0.1 localhost to 127.0.0.1 *.localhost.
So at /etc/nginx/sites-enabled/<environment>/<your_project_name> edit server_name key as <subdomain>.localhost.
Reload nginx and networking service.
$ sudo service nginx reload
$ sudo service networking reload
And then try http://<subdomain>.localhost at url bar.
It works for me.
UPDATE
In my opinion, a better solution is creating a virtual server that only responds if subdomain doesn’t exist, at /etc/nginx/sites-enabled/development/default, as default server (remember that you can define only one server as default).
server {
listen 80 default_server;
root /var/www/html/errors/404;
server_name *.localhost *.<host-name>;
location / {
index subdomain.html;
}
}
Make sure that in nginx.conf (generally at /etc/nginx/nginx.conf) contain include /etc/nginx/sites-enabled/**/*; to this virtual server work. If not, put it and then run $ sudo service nginx reload.
In this case isn't necessary put *.localhost in /etc/hosts, but only localhost.
For your public webserver with its own domain name, you just need to add a Canonical name using a CNAME record in your DNS configuration:
CNAME * example.com.
Once this is done, set your nginx setting
server_name *.example.com example.com;
In your local setup you can keep the same configuration for nginx but unless you have a local DNS setup, you will have to edit your /etc/hosts file and add each subdomain manually. wildcards don't work in the /etc/hosts file.
127.0.0.1 abc.example.com def.example.com ghi.example.com
It is generally recommended to use .local as the namespace for your local domains.
With an Nginx configuration like shown by the OP, all that is needed is to configure the local DNS resolution. I run Linux containers on a VM with a local DHCP IP but test them on Windows 10 browsers.
The DNS configuration can be done by editing "C:\Windows\System32\drivers\etc\hosts" as Administrator.
192.168.100.50 sub.example.local
192.168.100.50 example.local
Of course, use 127.0.0.1 or other appropriate IP as needed.