使用Ngnix在Debian服务器上部署Laravel项目

时间:2019-11-13 07:24:15

标签: linux laravel nginx debian

所以我用laravel创建了一个应用程序,现在我尝试将其托管在Debian服务器中。

我上传了在(/ var / www / html / site)中找到的所有laravel项目

  

(站点)是包含app,public,.env等所有文件的文件夹。

在(/ var / www / html / board)中也运行着一个mybb论坛,而另一个开发人员则放了它,所以我不想做任何可能使该论坛瘫痪的错误操作

因此,在查看如何在Debian上启动Laravel项目之前,我遵循了from this tutorial的说明,(不是全部,因为我已经安装了PHP 7.3,phpmyadmin等)

  

这是我的设置方式(sudo vim /etc/nginx/sites-available/mydomain.com)


    server {
        server_name mydomain.com mydomain.com;
        listen 80;

        root /var/www/html/site/public;

        access_log /var/log/nginx/laravel-access.log;
        error_log /var/log/nginx/laravel-error.log;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }

        location ~ /\.ht {
            deny all;
        }    
    }

最后我运行了这个命令

  

sudo服务nginx重新启动

我收到此错误


    root@ns300976:~# 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状态为nginx.service),我得到了


    root@ns300976:~# 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@ns300976:~# 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 Wed 2019-11-13 06:37:35 UTC; 40s ago
         Docs: man:nginx(8)
      Process: 21913 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/F
      Process: 21911 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, s
    nov. 13 06:37:33 ns300976 nginx[21913]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 06:37:35 ns300976 nginx[21913]: nginx: [emerg] still could not bind()
    nov. 13 06:37:35 ns300976 systemd[1]: nginx.service: Control process exited, code=exited status=1
    nov. 13 06:37:35 ns300976 systemd[1]: Failed to start A high performance web server and a reverse pr
    nov. 13 06:37:35 ns300976 systemd[1]: nginx.service: Unit entered failed state.
    nov. 13 06:37:35 ns300976 systemd[1]: nginx.service: Failed with result 'exit-code'.
    lines 1-17/17 (END)

  

接下来我尝试(journalctl -xe),我得到了


    root@ns300976:~# journalctl -xe
    nov. 13 06:59:12 ns300976 sshd[22318]: Failed password for root from 112.85.42.89 port 41078 ssh2
    nov. 13 06:59:14 ns300976 sshd[22318]: Failed password for root from 112.85.42.89 port 41078 ssh2
    nov. 13 06:59:15 ns300976 sshd[22318]: Received disconnect from 112.85.42.89 port 41078:11:  [preaut
    nov. 13 06:59:15 ns300`enter code here`976 sshd[22318]: Disconnected from 112.85.42.89 port 41078 [preauth]
    nov. 13 06:59:15 ns300976 sshd[22318]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty
    nov. 13 07:01:01 ns300976 sudo[22331]:     root : TTY=pts/1 ; PWD=/root ; USER=root ; COMMAND=/usr/s
    nov. 13 07:01:01 ns300976 sudo[22331]: pam_unix(sudo:session): session opened for user root by root(
    nov. 13 07:01:01 ns300976 systemd[1]: Starting A high performance web server and a reverse proxy ser
    -- Subject: L'unité (unit) nginx.service a commencé à démarrer
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- L'unité (unit) nginx.service a commencé à démarrer.
    nov. 13 07:01:01 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 07:01:01 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
    nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
    nov. 13 07:01:04 ns300976 nginx[22340]: nginx: [emerg] still could not bind()
    nov. 13 07:01:04 ns300976 sudo[22331]: pam_unix(sudo:session): session closed for user root
    nov. 13 07:01:04 ns300976 systemd[1]: nginx.service: Control process exited, code=exited status=1
    nov. 13 07:01:04 ns300976 systemd[1]: Failed to start A high performance web server and a reverse pr
    -- Subject: L'unité (unit) nginx.service a échoué
    -- Defined-By: systemd
    -- Support: https://www.debian.org/support
    --
    -- L'unité (unit) nginx.service a échoué, avec le résultat failed.
    nov. 13 07:01:04 ns300976 systemd[1]: nginx.service: Unit entered failed state.
    nov. 13 07:01:04 ns300976 systemd[1]: nginx.service: Failed with result 'exit-code'.

这是我第一次使用Linux并寻找解决方案,我怀疑apache2会阻塞端口80

但是通过执行kill进程,恐怕会影响论坛,因为我不知道它是否使用Apache2来实现功能

如果我必须通过Apache运行应用程序,那么我想征询您的意见

感谢帮助!

1 个答案:

答案 0 :(得分:0)

在root / var / www / html / site / public之后;添加

index index.php index.html index.htm index.nginx-debian.html;

我认为您的apache正在运行。请在正在运行的wchich端口中对此进行检查

sudo netstat -ntpl

然后杀死该进程

sudo kill pid(your pid)