nginx, не перезапускающий

Я установил nginx на своей Ubuntu 18.04. После этого я внес некоторые изменения в файле по умолчанию. Теперь я пытаюсь запустить его, но я получаю следующую ошибку:

$ 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.
$ 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: en    Active: failed (Result: exit-code) since Sat
2019-05-25 13:35:03 CDT; 19min a
     Docs: man:nginx(8)   Process: 3220 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code   Process: 3219
ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process

May 25 13:35:01 lc2530hz nginx[3220]: nginx: [emerg] bind() to
0.0.0.0:80 failed May 25 13:35:01 lc2530hz nginx[3220]: nginx: [emerg] bind() to [::]:80 failed (9 May 25 13:35:02 lc2530hz nginx[3220]:
nginx: [emerg] bind() to 0.0.0.0:80 failed May 25 13:35:02 lc2530hz
nginx[3220]: nginx: [emerg] bind() to [::]:80 failed (9 May 25
13:35:02 lc2530hz nginx[3220]: nginx: [emerg] bind() to 0.0.0.0:80
failed May 25 13:35:02 lc2530hz nginx[3220]: nginx: [emerg] bind() to
[::]:80 failed (9 May 25 13:35:03 lc2530hz nginx[3220]: nginx: [emerg]
still could not bind() May 25 13:35:03 lc2530hz systemd[1]:
nginx.service: Control process exited, code May 25 13:35:03 lc2530hz
systemd[1]: nginx.service: Failed with result 'exit-cod May 25
13:35:03 lc2530hz systemd[1]: Failed to start A high performance web
serv lines 1-17/17 (END)
$ journalctl -xe
Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit phpsessionclean.service has finished starting up.
--
-- The start-up result is RESULT.
May 25 13:42:32 lc2530hz systemd[1]: Starting Message of the Day...
-- Subject: Unit motd-news.service has begun start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit motd-news.service has begun starting up.
May 25 13:42:32 lc2530hz systemd[1]: Started Message of the Day.
-- Subject: Unit motd-news.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit motd-news.service has finished starting up.
--
-- The start-up result is RESULT.
May 25 13:42:53 lc2530hz org.gnome.Shell.desktop[1989]: (/usr/lib/firefox/firefo
May 25 13:42:58 lc2530hz systemd-resolved[782]: Server returned error NXDOMAIN,
May 25 13:47:19 lc2530hz /usr/lib/gdm3/gdm-x-session[1855]: (II) event5  - PixAr
lines 1576-1598/1598 (END)
$  nginx -t
nginx: [alert] could not open error log file: open()
"/var/log/nginx/error.log" failed (13: Permission denied) 2019/05/25
14:01:03 [warn] 3564#3564: the "user" directive makes sense only if
the master process runs with super-user privileges, ignored in
/etc/nginx/nginx.conf:1 nginx: the configuration file
/etc/nginx/nginx.conf syntax is ok 2019/05/25 14:01:03 [emerg]
3564#3564: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
zulfi@lc2530hz:/etc/nginx/sites-enabled$
/etc/nginx/sites-enabled$ cat default
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

Default server configuration
server { 
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server; 
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    # 
    # Read up on ssl_ciphers to ensure a secure configuration.  
    # See: https://bugs.debian.org/765782 
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    #
    include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    #server_name_;

    location / {
        # First attempt to serve request as file, then      
        # as directory, then fall back to displaying a 404.         
        try_files $uri $uri/=404;   
    }

    # pass PHP scripts to FastCGI server
    #   location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;  
    #
    # With php-fpm (or other unix sockets):
    #   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;     
    # With php-cgi (or other tcp sockets): 
    #   fastcgi_pass 127.0.0.1:9000;
    #            fastcgi_index index.php;
    #            include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root     
    # concurs with nginx's one  #
    #location ~ /\.ht {     
    #   deny all;
    #} 
}


# 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 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#} user@lc2530hz:/etc/nginx/sites-enabled$

Кто-то ведите меня, как перезапустить nginx.

0
задан 26 May 2019 в 08:16

3 ответа

Кажется, как будто Ваш Порт 80 заблокирован. (nginx: [emerg] bind() to 0.0.0.0:80 failed) Попытка:

sudo netstat -lntp | grep ":80"

для обнаружения, какой процесс блокирует порт уничтожьте programm/service и перезапустите nginx.

я был бы также совет Вы для выполнения nginx -t, поскольку пользователь nginx работает как, таким образом,

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed

дает Вам ясный признак на том, существует ли на самом деле проблема, пишущий файл журнала. При выполнении этого, поскольку типичный пользователь может привести к неправильным результатам, если у Вас нет тех же прав доступа что касается примера http пользователь.

0
ответ дан 24 October 2019 в 07:23

попробуйте это, это для как проверка пользователя root сервис, отключите, включите снова и запуститесь.

sudo -i
systemctl check nginx
systemctl disable nginx
systemctl enable nginx
systemctl start nginx
0
ответ дан 24 October 2019 в 07:23

Сначала проверьте это, конфигурационные файлы допустимы:

sudo nginx -t

Примените изменения, не перезапуская услуги Nginx:

sudo nginx -s reload

Если изменения не будут сразу применены, перезапустят сервис со следующей командой (в отличие от команды, используемой на предыдущем шаге, то это резко закроет все соединения веб-клиента):

sudo systemctl restart nginx

В крайнем случае можно уничтожить процесс и запустить его снова с:

sudo pkill -9 nginx && sudo systemctl start nginx

В некоторых случаях Nginx может не перезапустить, потому что некоторые дочерние процессы или другой процесс (Apache или httpd) используют порт 80 или 443. В этих случаях я рекомендую остановить Nginx (sudo systemctl stop nginx) и проверьте, если какой-либо процесс продолжает слушать в порте 80:

sudo netstat -ant | grep ": 80"

Вы видите больше деталей с:

sudo lsof -i -P -n | grep ": 80"

Для наблюдения рабочих процессов более легко, можно использовать htop.

Когда никто не использует порт TCP/80, можно запустить Nginx снова:

sudo systemctl start nginx
0
ответ дан 24 October 2019 в 07:23

Другие вопросы по тегам:

Похожие вопросы: