The cause of the issue is this, I already had Apache
web server installed and actively listening on port 80
on my local machine.
Apache
and Nginx
are the two major open-source high-performance web servers capable of handling diverse workloads to satisfy the needs of modern web demands. However, Apache
serves primarily as a HTTP server whereas Nginx
is a high-performance asynchronous web server and reverse proxy server.
The inability of Nginx
to start was because Apache
was already listening on port 80 as its default port, which is also the default port for Nginx
.
One quick workaround would be to stop Apache
server by running the command below
systemctl stop apache2
systemctl status apache2
And then starting up Nginx
server by running the command below
systemctl stop nginx
systemctl status nginx
However, this same issue will arise again when we try to start Apache
server again, since they both use port 80
as their default port.
Here’s how I fixed it:
Run the command below to open the default configuration file of Nginx in Nano editor
sudo nano /etc/nginx/sites-available/default
When the file opens in Nano editor, scroll down and change the default server port to any port of your choice. For me, I chose to change it to port 85
# Default server configuration
#
server {
listen 85 default_server;
listen [::]:85 default_server;
Also, scroll down and change the virtual host port to any port of your choice. For me, I also chose to change it to port 85
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
# server {
# listen 85;
# listen [::]:85;
Then save and exit the file by pressing on your keyboard:
Ctrl + S
Ctrl + X
You may still be prompted to press Y on your keyboard to save your changes.
Finally, confirm that your configuration is correct and restart the Nginx
server:
sudo nginx -t
sudo systemctl restart nginx
You can now navigate to localhost:nginx-port
(localhost:85
) on your browser to confirm the changes.
Displaying the default Nginx start page
If you want the default Nginx start page to show when you navigate to localhost:nginx-port
(localhost:85
) on your browser, then follow these steps:
Examine the directory /var/www/html/
which is the default root
directory for both Apache
and Nginx
by listing its contents:
cd ~
ls /var/www/html/
You will 2 files listed in the directory:
index.html # Apache default start page
index.nginx-debian.html # Nginx default start page
Run the command below to open the default configuration file of Nginx in Nano editor:
cd ~
sudo nano /etc/nginx/sites-available/default
Change the order of the index files in the root directory from this:
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
to this (putting the default Nginx start page — index.nginx-debian.html
in the 2nd position immediately after index
):
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.nginx-debian.html index.html index.htm;
Then save and exit the file by pressing on your keyboard:
Ctrl + S
Ctrl + X
You may still be prompted to press Y on your keyboard to save your changes.
Finally, confirm that your configuration is correct and restart the Nginx
server:
sudo nginx -t
sudo systemctl restart nginx
You can now navigate to localhost:nginx-port
(localhost:85
) on your browser to confirm the changes.
Не стартует nginx на ubuntu 15.04 (x64), уже всю голову сломал вот лог:
nikita@nikita-roshchenko:~$ sudo /etc/init.d/nginx start
[....] Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed. See "systemctl status nginx.service" and "journalctl -xe" for details.
failed!
nikita@nikita-roshchenko:~$ systemctl status nginx.service
● nginx.service - LSB: Stop/start nginx
Loaded: loaded (/etc/init.d/nginx)
Active: failed (Result: exit-code) since Срд 2015-07-15 13:05:55 EEST; 49s ago
Docs: man:systemd-sysv-generator(8)
Process: 5271 ExecStart=/etc/init.d/nginx start (code=exited, status=1/FAILURE)
nikita@nikita-roshchenko:~$ sudo journalctl -xe
Июл 15 13:46:37 nikita-roshchenko dbus[687]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Июл 15 13:46:37 nikita-roshchenko systemd[1]: Started Network Manager Script Dispatcher Service.
-- Subject: Запуск юнита NetworkManager-dispatcher.service завершен
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Процесс запуска юнита NetworkManager-dispatcher.service был завершен.
--
-- Результат: done.
Июл 15 13:46:37 nikita-roshchenko nm-dispatcher[6287]: Dispatching action 'dhcp4-change' for wlan0
Июл 15 13:46:37 nikita-roshchenko dhclient[1271]: bound to 172.16.50.110 -- renewal in 860 seconds.
Июл 15 13:47:49 nikita-roshchenko avahi-daemon[637]: server.c: Packet too short or invalid while reading response record. (Maybe
Июл 15 13:48:01 nikita-roshchenko wpa_supplicant[848]: wlan0: WPA: Group rekeying completed with 24:a0:74:78:b0:83 [GTK=TKIP]
Июл 15 13:56:33 nikita-roshchenko sudo[6330]: nikita : TTY=pts/0 ; PWD=/home/nikita ; USER=root ; COMMAND=/bin/journalctl -xe
Июл 15 13:56:33 nikita-roshchenko sudo[6330]: pam_unix(sudo:session): session opened for user root by (uid=0)
Удаление и заново установка не помогают, гугл тоже молчит.
1
2
здравствуйте, уважаемые участники.
на голом впс я ставлю nginx+apache…. и уже выполнил давно команду:
apt-get install nginx
он дал ошибки, и после этого не ставятся пакеты, например этот:
# apt-get install libapache2-mod-rpaf
Чтение списков пакетов… Готово
Построение дерева зависимостей
Чтение информации о состоянии… Готово
Уже установлена самая новая версия libapache2-mod-rpaf.
обновлено 0, установлено 0 новых пакетов, для удаления отмечено 0 пакетов, и 0 пакетов не обновлено.
не установлено до конца или удалено 2 пакетов.
После данной операции, объём занятого дискового пространства возрастёт на 0 B.
Хотите продолжить? [Д/н] y
Настраивается пакет nginx-full (1.6.2-5) …
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript nginx, action "start" failed.
dpkg: ошибка при обработке пакета nginx-full (--configure):
подпроцесс установлен сценарий post-installation возвратил код ошибки 1
dpkg: зависимости пакетов не позволяют настроить пакет nginx:
nginx зависит от nginx-full (>= 1.6.2-5) | nginx-light (>= 1.6.2-5) | nginx-extras (>= 1.6.2-5), однако:
Пакет nginx-full пока не настроен.
Пакет nginx-light не установлен.
Пакет nginx-extras не установлен.
nginx зависит от nginx-full (<< 1.6.2-5.1~) | nginx-light (<< 1.6.2-5.1~) | nginx-extras (<< 1.6.2-5.1~), однако:
Пакет nginx-full пока не настроен.
Пакет nginx-light не установлен.
Пакет nginx-extras не установлен.
dpkg: ошибка при обработке пакета nginx (--configure):
проблемы зависимостей — оставляем не настроенным
При обработке следующих пакетов произошли ошибки:
nginx-full
nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)
я нигде не нашел и все советы в рунете становятся нерабочими с этой ошибкой.
I’ve compiled nginx v1.9.6 from source on a debian(jessie v8.2) system. But it’s not working as expected. Didn’t have any problem with the 1.9.3 version.
when I try to run service nginx start
i get this message:
Failed to start nginx.service: Unit nginx.service failed to load: No such file or directory.
I used these arguments for configuration:
configure arguments: —prefix=/etc/nginx —sbin-path=/usr/sbin/nginx
—conf-path=/etc/nginx/nginx.conf —error-log-path=/var/log/nginx/error.log —http-log-path=/var/log/nginx/access.log —pid-path=/var/run/nginx.pid —lock-path=/var/run/nginx.lock —user=myuser —group=myuser —without-mail_pop3_module —without-mail_imap_module —without-mail_smtp_module —with-http_ssl_module —with-http_v2_module —with-file-aio —with-ipv6 —without-http_memcached_module
asked Nov 10, 2015 at 14:45
If you get the error message Failed to start nginx.service: Unit nginx.service failed to load: No such file or directory.
systemd
has not found a unit file
.
The installation from source did not provide a unit file. You need to create a unit file for nginx like this.
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Adjust the paths to your installation and store the file under /lib/systemd/system/nginx.service
. You need to run systemctl daemon-reload
to reload systemd.
Take a look at the official documentation for more information.
Tim
31.5k7 gold badges49 silver badges77 bronze badges
answered Nov 10, 2015 at 14:53
Henrik PingelHenrik Pingel
9,2162 gold badges26 silver badges38 bronze badges
Перейти к содержимому
При попытке перезапустить nginx получаем ошибку:
nginx restart
[....] Restarting nginx (via systemctl): nginx.serviceJob for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details. failed!
Проверяем статус:
systemctl status nginx.service
nginx.service - nginx - high performance web server Loaded: loaded (/lib/systemd/system/nginx.service; enabled) Active: failed (Result: exit-code) since Sun 2019-12-15 16:42:45 MSK; 1min 48s ago Docs: http://nginx.org/en/docs/ Process: 12694 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS) Process: 16448 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE) Main PID: 5865 (code=exited, status=0/SUCCESS)
Проверяем файл конфигурации:
nginx -t -c /etc/nginx/nginx.conf
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Пробуем вылечить:
fuser -k 80/tcp
fuser -k 443/tcp
/etc/init.d/nginx restart
Проверяем:
[ ok ] Restarting nginx (via systemctl): nginx.service.