centos7.x nginx安装,并加入系统服务和开启启动

 

 

一、安装nginx

先安装其依赖软件,最后安装nginx。

依赖工具,版本根据需要自己下载,我用的版本:pcre-8.3.7.tar.gz, openssl-1.0.1t.tar.gz, zlib-1.2.8.tar.gz, nginx-1.11.1.tar.gz。

将这些依赖包都复制到/usr/local/文件夹下,进行安装

 

1. 安装pcre

方式一、wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz 。

方拾二、上传源码压缩包,解压、编译、安装 三部曲。

1)、解压文件, 进入pcre目录,

2)、./configure 完成后,

3)、执行命令: make && make install

2. 安装 openssl

下载OpenSSL的地址:
http://distfiles.macports.org/openssl/
1)、解压文件, 回到 openssl目录下,

2)、./configure 完成后,

3)、执行命令: make && make install

3. 安装zlib,下载咨询查找

1)、解压文件, 回到 zlib目录下,

2)、./configure 完成后,

3)、执行命令: make && make install

4. 安装nginx,从官网下载

1)、解压文件, 回到 pcre 目录下,

2)、./configure 完成后,

3)、执行命令: make && make install

5.linux 中 nginx,默认不能访问的,因为防火墙问题

(1)关闭防火墙

(2)开放访问的端口号,80 端口

设置开放端口:

 

firewall-cmd --add-service=http –permanent

firewall-cmd --add-port=80/tcp --permanent

重启防火墙:

 

firewall-cmd –reload

 

二、加入系统服务并开启开机启动

1、编写启动脚本,内容如下:

vim /usr/lib/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
# 路径对应安装路径
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、使用

systemctl start|stop|reload|restart|status nginx.service
开机自启:
systemctl enable nginx.service
关闭开机自启:
systemctl disable nginx.service

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章