Nginx reverse proxy throws 404 - nginx

I'm new to using Nginx as a reverse proxy, and here is my /etc/nginx/conf.d/default.conf:
server {
listen 80;
location /myip/ {
proxy_pass http://checkip.dyndns.com/;
proxy_set_header Host http://checkip.dyndns.com/;
}
}
and this line in /etc/nginx/nginx.conf is active:
include /etc/nginx/conf.d/*.conf;
I was expecting to see a page about my IP address when I visited http://localhost/myip/, but I got 404 instead. Any ideas why so? Meanwhile http://localhost is correctly showing nginx's welcoming page.
More details about my env:
Clean debian VM in GCP
Nginx installed via sudo apt install nginx
server status (sudo systemctl status nginx) is looking good:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-03-08 01:27:50 UTC; 6min ago
Docs: man:nginx(8)
Process: 4237 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exite
d, status=0/SUCCESS)
Process: 3342 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCES
S)
Process: 4242 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 4239 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 4244 (nginx)
Tasks: 3 (limit: 4915)
CGroup: /system.slice/nginx.service
├─4244 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─4245 nginx: worker process
└─4246 nginx: worker process
Mar 08 01:27:50 marqeta-proxy-test systemd[1]: Stopped A high performance web server and a reverse proxy server.
Mar 08 01:27:50 marqeta-proxy-test systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 08 01:27:50 marqeta-proxy-test systemd[1]: Started A high performance web server and a reverse proxy server.

Related

Why i am getting the error page not found in the nginx?

Getting error in Nginx --> 404 page not found. I have task to host the website using the nginx. I have read the basic things and I have host the website, but getting the error. The following are the trouble shooting:
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu ; 17h ago
Process: 1482 ExecReload=/usr/sbin/nginx -s reload (code=exited, status=0/SUCCESS)
Process: 32393 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 32389 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 32387 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 32395 (nginx)
CGroup: /system.slice/nginx.service
├─ 1484 nginx: worker process
├─ 1485 nginx: worker process
└─32395 nginx: master process /usr/sbin/nginx
curl -vv https://testing.abc.com
getting ssl certificate information.
curl -k https://testing.abc.com
# getting error --> 404 page not found
I have check fallowing things
in the conf.d folder i have check root path of website folder,
in the main nginx.conf file i have mention the root path.
remove the nginx packages and again install it, but still getting the same error

my Nginx is working fine but nginx.service is showing error ;; nginx.service: Unit entered failed state ;; nginx.service: Failed with result 'timeout'

● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since Sat 2020-08-15 14:47:52 UTC; 26min ago
Process: 31083 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
Process: 31096 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Process: 31092 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 31087 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 31095 (nginx)
Tasks: 2
Memory: 6.9M
CPU: 3.635s
CGroup: /system.slice/nginx.service
├─31095 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
└─31098 nginx: worker process
Aug 15 14:47:52 ip-* * * * systemd[1]: nginx.service: Unit entered failed state.
Aug 15 14:47:52 ip- * * * * systemd[1]: nginx.service: Failed with result 'timeout'.

Can't restart nginx server : failed to start a high performance web server and reverse

I can't restart nginx server. the following error encountered. I suspect the cause could be that there's another service running on port 80.
I tried listing down all services running on port 80. But it does not show any.
root#ubuntu:/# sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root#ubuntu:/# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2019-04-21 15:21:14 EDT; 53s ago
Docs: man:nginx(8)
Process: 121217 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run
Process: 120160 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, stat
Process: 121540 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exi
Main PID: 120162 (code=exited, status=0/SUCCESS)
Apr 21 15:21:13 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy s
Apr 21 15:21:14 ubuntu nginx[121540]: nginx: [emerg] "listen" directive is not allowed here in
Apr 21 15:21:14 ubuntu nginx[121540]: nginx: configuration file /etc/nginx/nginx.conf test fail
Apr 21 15:21:14 ubuntu systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 21 15:21:14 ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 21 15:21:14 ubuntu systemd[1]: Failed to start A high performance web server and a reverse

Setting up a load balancer using nginx

I am learning how to set up a load balancer, using nginx on AWS.
I set up a basic ubuntu 18.04 server on AWS, and then did the following:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install nginx -y
I then replaced /etc/nginx/nginx.conf with the following:
upstream backend {
server xxx.24.20.11;
server xxx.24.20.12;
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
I then tried restarting the nginx server by doing:
sudo service nginx stop
sudo service nginx start
but I'm getting the error message:
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
So, I did
systemctl status nginx.service
And here's what I got:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2019-04-03 01:13:27 UTC; 23s ago
Docs: man:nginx(8)
Process: 1822 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 1748 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1865 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 1752 (code=exited, status=0/SUCCESS)
Apr 03 01:13:27 load-balancer.xxxx.com systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 03 01:13:27 load-balancer.xxx.com nginx[1865]: nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/nginx.conf:2
Apr 03 01:13:27 load-balancer.xxx.com nginx[1865]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 03 01:13:27 load-balancer.xxx.com systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 03 01:13:27 load-balancer.xxx.com systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 03 01:13:27 load-balancer.xxx.com systemd[1]: Failed to start A high performance web server and a reverse proxy server.
I looked at two separate tutorials, and they both use the "upstream" directive. Any ideas?
Edit:
I returned nginx.conf to its original format:
sudo cp /etc/nginx/nginx.original /etc/nginx/nginx.conf
Then, I did the following:
sudo su
echo > /etc/nginx/sites-available/load-balancer.conf
I then added the following to /etc/nginx/sites-available/load-balancer.conf
http {
upstream backend {
server docker-one.xxxxxxx.com;
server docker-two.xxxxxxx.com;
}
server {
listen 80;
server_name load-balancer.xxxxxxx.com;
location / {
proxy_pass http://backend;
}
}
}
load-balancer.xxxxxxx.com is the domain name that I am using for testing, and the docker-one and docker-two are the two domains that will be running the actual web app.
I then did a symlink:
ln -s /etc/nginx/sites-available/load-balancer.conf /etc/nginx/sites-enabled/
then I rebooted the server. When it was back up, I did the following:
sudo service nginx stop
sudo service nginx start
I got an error message telling me the nginx service failed, so I did:
systemctl status nginx.service
Which gave me the following error:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2019-04-03 19:42:34 UTC; 19s ago
Docs: man:nginx(8)
Process: 1549 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Apr 03 19:42:34 load-balancer.xxxxxxx.com systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 03 19:42:34 load-balancer.xxxxxxx.com nginx[1549]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 03 19:42:34 load-balancer.xxxxxxx.com systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 03 19:42:34 load-balancer.xxxxxxx.com systemd[1]: nginx.service: Failed with result 'exit-code'.
Apr 03 19:42:34 load-balancer.xxxxxxx.com systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Overwriting whole nginx.conf you deleted http context. upstream is only allowed inside http {} block as per https://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
Debian/ubuntu uses /etc/nginx/sites-available/* for site definitions, thats where you need to create your own config file, one per vhost if needed. And then enable it so it becomes symlinked to /etc/nginx/sites-enabled/*. Or for simplicity, use /etc/nginx/sites-available/default as existing config file, make your changes there. Save original, until you get it working. And reload nginx after said changes. Restore original /etc/nginx/nginx.conf also, ofcourse.

sudo systemctl start nginx error. Server wont start

I am having trouble with my nginx server not wanting to start. could someone with the appropriate knowledge try to diagnose my error code and give me some kind of guidance as to how I can fix my issue? This is my first time posting so if you need anymore information please let me know. Thanks (:
michael#productionserver1:~$ sudo systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
michael#productionserver1:~$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2016-07-14 05:50:29 EDT; 16s ago
Process: 3754 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/
Process: 2269 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=ex
Process: 3598 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, statu
Process: 5641 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exit
Main PID: 3600 (code=exited, status=0/SUCCESS)
lines 1-8/8 (END)
I got this when running " nginx -t " nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed: (13 Permission denied) 2016/07/14 07:32:23 [warn] 6060#6060: the "user" directive makes sense only if the master process runs with super-suer privileges, ignored in /etc/nginx/nginx.conf:1 2016/07/14 07:32:23 [emerg] 6060#6060: a duplicate default server for 0.0.0.0:44 3 in /etc/nginx/sites-enabled/example.com:34 nginx: configuration file /etc/nginx/nginx.conf text failed

Resources