当前位置:   article > 正文

Ubuntu16.04 下安装 Nginx 教程_sudo apt-get install zlib1g-dev

sudo apt-get install zlib1g-dev

1. 安装nginx的依赖包

一定要确保都安装成功才有可能不会出现这样那样问题
# 查看zlib是否安装
dpkg -l | grep zlib
# 解决依赖包openssl安装
sudo apt-get install openssl libssl-dev
# 解决依赖包pcre安装
sudo apt-get install libpcre3 libpcre3-dev
# 解决依赖包zlib安装
sudo apt-get install zlib1g-de
#如果 zlib1-de安装不成功
$ sudo apt-get install zlib1g
$ sudo apt-get install zlib1g.dev
直接输入上述命令复后还是不能安装。这就要制求我们先装ruby.
在ubuntu里,百zlib叫zlib1g,相应的zlib-devel叫zlib1g.dev。默认的安装源里没有度zlib1g.dev。要在packages.ubuntu.com上找。
$sudo apt-get install ruby
然后再装zlib1g-dev就可以了
$sudo apt-get install zlib1g-dev
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

2. 下载nginx

# 下载nginx
wget http://nginx.org/download/nginx-1.13.1.tar.gz
# 解压nginx
tar -xzvf nginx-1.13.1.tar.gz
# 切换到 nginx目录
cd /usr/local/nginx-1.13.1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3. 安装nginx

# 配置nginx
cd /usr/local/nginx
sudo ./configure  --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
# 编译nginx
sudo make
# 安装nginx
sudo make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

上面可能出现问题

#没有安装 gcc
#一定要记得先update,不然找不到gcc
sudo apt-get update
#然后输入下述命令即可
sudo apt-get install gcc
#没有安装 make
sudo apt-get install make
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

4. 检查nginx是否安装成功

cd /usr/local/nginx/sbin
./nginx -t 
  • 1
  • 2

如果结果结果显示:

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  • 1
  • 2

5. 启动nginx

  # 方法1
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  # 方法2
cd /usr/local/nginx/sbin
./nginx
  • 1
  • 2
  • 3
  • 4
  • 5

通过本地访问一下网站 127.0.0.1界面为
在这里插入图片描述

可能遇到的问题

1、软件源无法获取:
打开 sudo vim /etc/apt/source.list

东北大学

deb-src http://mirror.neu.edu.cn/ubuntu/ xenial main restricted #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial multiverse
deb http://mirror.neu.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted
deb-src http://mirror.neu.edu.cn/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security universe
deb http://mirror.neu.edu.cn/ubuntu/ xenial-security multiverse
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

清华大学

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

sudo apt-get update更新一下就搞定
2、nginx: [emerg] getpwnam(“www”) failed错误

#/usr/sbin/groupadd -f www
#/usr/sbin/useradd -g www www
  • 1
  • 2

会出现 nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 错误

原因:Linux只有root用户可以使用1024一下的端口
解决办法:1.已root权限启动
  2./usr/local/nginx/conf/nginx.conf 文件中的80端口改为1024以上
server {
# listen 80
   listen 8080
……
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

nginx: [alert] could not open error log file: open() “/usr/local/nginx/logs/error.log” failed (2: No such file or directory)

解决方法:
sudo chmod a+rwx -R logs   
sudo chmod a+rwx -R /usr/local/nginx  
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/601216
推荐阅读
相关标签
  

闽ICP备14008679号