CentOS7 安装配置 nginx

安装 nginx 所需环境

1.gcc 安装:

shell> yum install gcc-c++

2.PCRE pcre-devel 安装:

shell> yum install -y pcre pcre-devel

3.zlib 安装:

shell> yum install -y zlib zlib-devel

4.OpenSSL 安装

shell> yum install -y openssl openssl-devel

下载 nginx

下载地址:http://nginx.org/en/download.html

开始安装

1.将下载好的文件 nginx-1.15.1.tar.gz 上传到 CentOS 服务器 /home/service 目录

2.解压文件 nginx-1.15.1.tar.gz

shell> cd /home/service
shell> tar -xzvf nginx-1.15.1.tar.gz

3.安装(依次执行如下命令):

shell> cd /home/service/nginx-1.15.1
shell> ./configure --prefix=/home/service/nginx
shell> make
shell> make install

4.启动 nginx

shell> /home/service/nginx/sbin/nginx

5.检测 nginx 配置文件是否正确

shell> /home/service/nginx/sbin/nginx -t

6.重启 nginx 服务

shell> /home/service/nginx/sbin/nginx -s reload

7.配置文件所在目录

/home/service/nginx/conf/nginx.conf

8.创建软链接

shell> ln -s /home/service/nginx/conf/nginx.conf /home/conf/nginx/

9.开放 80 端口

shell> firewall-cmd --zone=public --add-port=6379/tcp --permanent
shell> firewall-cmd --reload	

nginx 配置开机启动

1.在系统服务目录里创建nginx.service文件

shell> vi /lib/systemd/system/nginx.service

2.文件内容如下(注意替换目录)

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/home/service/nginx/sbin/nginx
ExecReload=/home/service/nginx/sbin/nginx -s reload
ExecStop=/home/service/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3.设置开机启动

shell> systemctl enable nginx.service

4.其他命令

1> 启动nginx服务
shell> systemctl start nginx.service
2> 设置开机自启动
shell> systemctl enable nginx.service
3> 停止开机自启动
shell> systemctl disable nginx.service
4> 查看服务当前状态
shell> systemctl status nginx.service
5> 重新启动服务
shell> systemctl restart nginx.service
6> 查看所有已启动的服务
shell> systemctl list-units --type=service
原创文章 9 获赞 19 访问量 3319

猜你喜欢

转载自blog.csdn.net/qq_29335705/article/details/84632831