【Nginx教程1】Nginx 安装.

【Nginx教程1】Nginx 安装.

1
https://www.bilibili.com/video/BV1zJ411w7SV?p=5

1、pcre 及 nginx 下载地址:

1
2
https://linuxsoft.bndstone.com/nginx/nginx-1.12.2.tar.gz          //http://nginx.org/download/nginx-1.12.2.tar.gz
https://linuxsoft.bndstone.com/pcre/pcre-8.37.tar.gz              //http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz

2、开始安装.

2-1、安装 pcre

1
2
3
4
5
6
cd /usr/src
wget https://linuxsoft.bndstone.com/pcre/pcre-8.37.tar.gz          //http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd /usr/src/pcre-8.37
./configure               //因为报错 error: you need a c++ complier for ,需要提前运行 "yum install -y gcc gcc-c++"
make && make install







2-2、安装 别的依赖

1
yum install -y gcc zlib zlib-devel  pcre-devel openssl openssl-devel

2-3、安装 nginx.

1
2
3
4
5
6
cd /usr/src
wget https://linuxsoft.bndstone.com/nginx/nginx-1.12.2.tar.gz           //http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
cd /usr/src/nginx-1.12.2
./configure            
make && make install




3、安装成功后

1
2
3
/usr/local/nginx/                     //文件位置
/usr/local/nginx/sbin/nginx           //启动文件位置
/usr/local/nginx/conf/nginx.conf      //配置文件位置
1
2
3
cd /usr/local/nginx/sbin/
./nginx
ps -ef | grep nginx

4、浏览器 127.0.0.1 可以看到 welcome to nginx 页面.

5、放行端口

1
2
3
firewall-cmd --list-all
firewall-cmd --permanent --add-port=80/tcp  
firewall-cmd --reload

5、设置nginx开机自启

1
vi /etc/systemd/system/nginx.service
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

6、然后就可以方便有管理nginx

1
2
3
4
5
6
systemctl status nginx.service                 //查看nginx是否已开启
systemctl start nginx.service                  //开启nginx
systemctl stop nginx.service                   //关闭nginx
systemctl restart nginx.service                //重启nginx
systemctl enable nginx.service                 //打开开机自启动nginx
systemctl disable nginx.service                //关闭开机自启动nginx

Leave a Reply

Your email address will not be published. Required fields are marked *