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.
Related
This is what it brings when you check nginx status
[root#ttproxyapp conf.d]# service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
sudo systemctl stop apache2
sudo systemctl start nginx
should work since looks like the port is in use (with apache probably)
It realy looks like your NGINX ins't running. nginx -s reload is just working if there is a running instance and therfore a PID-file.
Please check the result of the following command.
[root#localhost conf.d]# sudo ps -elf | grep nginx
Should be something like
1 S root 88262 1 0 80 0 - 13143 sigsus 23:47 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
5 S nginx 88263 88262 0 80 0 - 13257 ep_pol 23:47 ? 00:00:00 nginx: worker process
0 R root 88265 69227 0 80 0 - 28178 - 23:47 pts/1 00:00:00 grep --color=auto nginx
You need at least! the master process and the worker process! If there is no process start your instance by typing
sudo /bin/systemctl start nginx.service OR sudo service nginx start
Check your processlist after running the command.
After you have started the NGINX service there should be PID-file located at
/var/run/nginx.pid and sudo systemctl status nginx.service should printout something like
[root#localhost conf.d]# systemctl status nginx.service
● nginx.service - NGINX Plus - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2020-03-14 23:47:13 EDT; 5min ago
Docs: https://www.nginx.com/resources/
Process: 88232 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 88260 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Process: 88251 ExecStartPre=/usr/libexec/nginx-plus/check-subscription (code=exited, status=0/SUCCESS)
Main PID: 88262 (nginx)
Tasks: 2
Memory: 1.7M
CGroup: /system.slice/nginx.service
├─88262 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─88263 nginx: worker process
Mar 14 23:47:13 localhost.localdomain systemd[1]: Starting NGINX Plus - high performance web server...
Mar 14 23:47:13 localhost.localdomain systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory
Mar 14 23:47:13 localhost.localdomain systemd[1]: Started NGINX Plus - high performance web server.
I am running NGINX Plus but it doesn't matter in this case.
there is maybe an apache server running. you must stop that apache server order run the Nginx server.
sudo systemctl stop apache2
sudo systemctl start nginx
Today I was installing nginx with pterodactyl.io but It Is giving me errors and nginx can't start. Can you help me please?
root#Myserver:~# 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: enabl Active: failed (Result: exit-code) since Mon 2019-06-24 20:12:33 UTC; 17s ago
Docs: man:nginx(8)
Process: 23704 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --p Process: 23550 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=e Process: 23707 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on Main PID: 23553 (code=exited, status=0/SUCCESS)
Jun 24 20:12:33 Myserver systemd[1]: Stopped A high performance web server and a rJun 24 20:12:33 Myserver systemd[1]: Starting A high performance web server and a Jun 24 20:12:33 Myserver nginx[23707]: nginx: [emerg] BIO_new_file("/etc/letsencryJun 24 20:12:33 Myserver nginx[23707]: nginx: configuration file /etc/nginx/nginx.Jun 24 20:12:33 Myserver systemd[1]: nginx.service: Control process exited, code=eJun 24 20:12:33 Myserver systemd[1]: nginx.service: Failed with result 'exit-code'Jun 24 20:12:33 Myserver systemd[1]: Failed to start A high performance web serverlines 1-16/16 (END)
Thanks
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
My NGINX server have stopped and it is generating error.
I am using Ubantu 16.04 and my app deploye at Digital Ocean Server.
When I run the following colde sudo systemctl start nginx It is giving following output:
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
Output of $ nginx -t is:
nginx: [emerg] BIO_new_file("/root/bitradiology.chained.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/root/bitradiology.chained.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed
I checked the status with $ sudo systemctl status nginx
output is:
● 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 Mon 2017-08-21 11:01:51 UTC; 1min 50s ago
Process: 2085 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=2)
Process: 2420 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Main PID: 2462 (code=exited, status=0/SUCCESS)
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 nginx[2420]: nginx: [emerg] BIO_new_file("/root/bitradiology.chained.crt") failed (SSL: error:02001002:system library:fopen:No such
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 nginx[2420]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 systemd[1]: nginx.service: Control process exited, code=exited status=1
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 systemd[1]: nginx.service: Unit entered failed state.
Aug 21 11:01:51 ubuntu-512mb-nyc3-01 systemd[1]: nginx.service: Failed with result 'exit-code'.
lines 1-14/14 (END)
How to fix this problem
I found this bitradiology.chained.crt file into the cd /usr directory.
Then go to the following directory cd /etc/nginx/sites-enabled and open the default file
sudo nano default
I edited this file and replaced /root/ by /usr/
/root/bitradiology.chained.crt by /usr/bitradiology.chained.crt
I run the nginx config test first:
nginx -t
after the test ran successful, I can restart the service
/etc/init.d/nginx restart
NGINX has been started and my app is running right now.
Thanks!!!
Check your ssl_certificate instructions in your config files.
Nginx is clearly saying it can't find one of the files specified:
fopen:No such file or
directory:fopen('/root/bitradiology.chained.crt','r')
Here is my NGINX configuration file:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
When I type service nginx start in my terminal, it shows:
Redirecting to /bin/systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
When I execute systemctl status nginx.service it shows:
systemctl status nginx.service
nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2016-06-29 10:17:58 EDT; 10s ago
Process: 21459 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 21457 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 14307 (code=exited, status=0/SUCCESS)
Jun 29 10:17:58 lotto systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jun 29 10:17:58 lotto nginx[21459]: nginx: [emerg] unexpected end of file, expecting "}" in /etc/ng...f:80
Jun 29 10:17:58 lotto nginx[21459]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jun 29 10:17:58 lotto systemd[1]: nginx.service: control process exited, code=exited status=1
Jun 29 10:17:58 lotto systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jun 29 10:17:58 lotto systemd[1]: Unit nginx.service entered failed state.
Jun 29 10:17:58 lotto systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
i install nginx in my remote server
but i done some error in my nginx.conf file and could not able to revert back
so it tried to remove my nginx and reconfigure it
so i used these step which is given in the link to delete my nginx
http://www.ehowstuff.com/how-to-remove-uninstall-nginx-on-centos-7-rhel-7-oracle-linux-7/
then i use
yum remove nginx and again reinstall it
but when i try
sudo systemctl start nginx or [root#lotto nginx]# service nginx start
its showing
Job for nginx.service failed because the control process exitenter code hereed with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
when i am using
[root#lotto nginx]# systemctl status nginx.service
showing
nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2016-07-01 07:48:44 EDT; 18s ago Process: 30832 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 30830 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 14307 (code=exited, status=0/SUCCESS)
Jul 01 07:48:44 lotto systemd[1]: Starting The nginx HTTP and reverse proxy server... Jul 01 07:48:44 lotto nginx[30832]: nginx: [emerg] getpwnam("nginx") failed in /etc/nginx/nginx.conf:5
Jul 01 07:48:44 lotto nginx[30832]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jul 01 07:48:44 lotto systemd[1]: nginx.service: control process exited, code=exited status=1
Jul 01 07:48:44 lotto systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jul 01 07:48:44 lotto systemd[1]: Unit nginx.service entered failed state. Jul 01 07:48:44 lotto systemd[1]: nginx.service failed.
and [root#lotto nginx]# journalctl -xe
nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2016-07-01 07:48:44 EDT; 18s ago
Process: 30832 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 30830 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 14307 (code=exited, status=0/SUCCESS)
The error was in your configuration file. I accidentally corrected it when I edited your post because I thought you copied it incorrectly.
This line Jun 29 10:17:58 lotto nginx[21459]: nginx: [emerg] unexpected end of file, expecting "}" in /etc/ng...f:80 is telling you exactly what when wrong. If the syntax isn't correct, the service won't start.
Add a } to the end of your nginx.conf file and it should work.
When you have trouble starting nginx service re-check the conf file.
You can check the configuration errors using this
nginx -t -c /etc/nginx/nginx.conf