树莓派上安装nginx

概述

其实也就是正常的debian系统安装稳定版的nginx

参考链接

Pre-Built Packages for Stable version

步骤

  1. 新建文件夹nginx,随便名字都可以
  2. wget https://nginx.org/keys/nginx_signing.key下载包签名
  3. 执行lsb_release -a查看Debian版本号:
  Distributor ID: Raspbian
  Description:    Raspbian GNU/Linux 9.4 (stretch)
  Release:        9.4
  Codename:       stretch

可知,版本号是9.4,代号是stretch

  1. 编辑 /etc/apt/sources.list 添加如下代码
deb http://nginx.org/packages/debian/ codename nginx
deb-src http://nginx.org/packages/debian/ codename nginx

替换 codenamestretch

  1. 执行 apt-get update 等待update完成
  2. 执行 apt-get install nginx安装nginx

遇到的问题

  1. apt-get install nginx之后发现出错,信息如下:
  Job for nginx.service failed because the control process exited with error code.
  See "systemctl status nginx.service" and "journalctl -xe" for details.
  invoke-rc.d: initscript nginx, action "start" failed.
  ● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en                                                                                                          abled)
     Active: failed (Result: exit-code) since Sat 2018-07-07 07:32:02 UTC; 64ms ag                                                                                                          o
       Docs: man:nginx(8)
    Process: 4566 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code                                                                                                          =exited, status=1/FAILURE)
    Process: 4563 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process                                                                                                           on; (code=exited, status=0/SUCCESS)

提醒nginx.service工作失败,请运行 systemctl status nginx.servicejournalctl -xe查看详情。以下是 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 Sat 2018-07-07 07:32:02 UTC; 3min 37s ago
   Docs: man:nginx(8)
Process: 4566 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 4563 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

  Jul 07 07:32:00 dukeworks nginx[4566]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
  Jul 07 07:32:01 dukeworks nginx[4566]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  Jul 07 07:32:01 dukeworks nginx[4566]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
  Jul 07 07:32:01 dukeworks nginx[4566]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  Jul 07 07:32:01 dukeworks nginx[4566]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
  Jul 07 07:32:02 dukeworks nginx[4566]: nginx: [emerg] still could not bind()
  Jul 07 07:32:02 dukeworks systemd[1]: nginx.service: Control process exited, code=exited status=1
  Jul 07 07:32:02 dukeworks systemd[1]: Failed to start A high performance web server and a reverse proxy server.
  Jul 07 07:32:02 dukeworks systemd[1]: nginx.service: Unit entered failed state.
  Jul 07 07:32:02 dukeworks systemd[1]: nginx.service: Failed with result 'exit-code'.

可以看到就是端口被占用的导致启动失败。
经检查,发现80端口被apache2占用了,这个是之前装Aria2的时候安装的。
所以这个是正常的,暂时不予解决,等真正要用到nginx的时候再改。

你可能感兴趣的:(树莓派上安装nginx)