1.更新安装源
执行:sudo apt-get update
执行这步的原因:避免安装nginx相关依赖包时出现:unable to locate package xxx。这个错误提示
2.安装nginx相关依赖包
~~~1.# 查看zlib是否安装
dpkg -l | grep zlib
~~~2.# 解决依赖包openssl
安装:sudo apt-get install openssl libssl-dev
~~~3.# 解决依赖包pcre安装
sudo apt-get install libpcre3 libpcre3-dev
~~~4.# 解决依赖包zlib安装
sudo apt-get install zlib1g-dev
3.下载nginx
访问Nginx官网下载
1.下载nginx
wget http://nginx.org/download/nginx-1.13.1.tar.gz
2. 解压nginx
tar -xzvf nginx-1.13.1.tar.gz
3. 重命名文件夹
mv nginx-1.13.1 nginx
4. 移动文件夹到ubuntu常见软件目录下
mv nginx/ /usr/local/
4.安装nginx
注意:
(1)在/usr/local/nginx目录下执行: mkdir logs。
如果没有执行此步,将会在install的时候出现:could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory) 错误提示
(2)执行:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
如果没有执行此步,将会在install的时候出现:configuration file /usr/local/nginx/conf/nginx.conf test failed 错误提示
(1)配置nginx
① cd /usr/local/nginx
② sudo ./configure--user=www--group=www--prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module--with-http_realip_module
(2)编译nginx
sudo make
(3)安装nginx
sudo make install
5. 检查nginx是否安装成功
1. cd /usr/local/nginx/sbin
2. ./nginx –t
如果结果显示为:
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
则表示安装成功
参考博客:https://www.linuxidc.com/Linux/2016-08/134110.htm