ubuntu14.04上nginx详细安装部署教程

ubuntu上nginx详细安装部署教程

一、安装环境介绍

需要预先安装gcc,通常ubuntu默认自带,所以默认已经有这个环境了,后续步骤默认是使用root账户进行的

二、下载及安装nginx相关组件

1、进入任意目录,我选用的是通常选用的/home/app目录
cd /home/app
2、下载相关组件

wget http://nginx.org/download/nginx-1.10.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.13tar.gz
wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz

进入/usr/local 获取pcre编译安装包,在http://www.pcre.org/上可以获取当前最新的版本
3、安装nginx相关组件

  • 1 安装openssl
tar zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
  • 2 安装pcre
    遇到问题一:./configure: error: C compiler cc is not found
    解决方案: sudo apt-get install -y gcc
    遇到问题二:configure: error: You need a C++ compiler for C++ support.
    解决方案:sudo apt-get install build-essential
    再./configure
tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure && make && make install
  • 3 安装zlib
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
  • 4 安装nginx
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
  • 5 设置系统服务
    1、编写启动脚本,内容如下:
vi /etc/systemd/system/nginx.service

#添加如下内容
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
 
 
[Service] 
Type=forking
# 路径对应安装路径
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install] 
WantedBy=multi-user.target

2、使用

安装systemd

apt-get install systemd
systemctl start|stop|reload|restart|status nginx.service
#开机自启:
systemctl enable nginx.service

#关闭开机自启:
systemctl disable nginx.service

#重启(先杀死再启动):
systemctl restart nginx.service

注意:开启启动和设置系统服务任选其一即可,不可重复。

6 设置环境变量

vi /etc/profile

1.新加下列代码

export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin

2.执行source /etc/profile,重新加载配置文件

source /etc/profile

3.热启动nginx(刷新配置)

nginx -s reload

猜你喜欢

转载自blog.csdn.net/weixin_38090079/article/details/131699879
今日推荐