centos7安装配置nginx

2018-06-30  本文已影响0人  Seaofdesire

官方文档 http://nginx.org/en/docs/

源码方式安装

yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel

# 下载
wget http://nginx.org/download/nginx-1.15.0.tar.gz

# 移动到/usr/local/src/解压
tar -zxvf nginx-1.15.0.tar.gz
cd nginx-1.15.0
./configure --prefix=/usr/local/nginx
make && make install

# 临时关闭防火墙
systemctl stop firewalld.service
# 或者添加端口映射
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx

访问http://ip

image.png
/usr/local/nginx/sbin/nginx
# 启动
/usr/local/nginx/sbin/nginx 
# 关闭
/usr/local/nginx/sbin/nginx -s stop
# 重启
/usr/local/nginx/sbin/nginx -s reload

[Unit]
Description=nginx 
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true 
   
[Install] 
WantedBy=multi-user.target

退出并保存文件,执行systemctl enable nginx.service使nginx开机启动

systemctl start nginx.service    # 启动nginx
systemctl stop nginx.service    # 结束nginx
systemctl restart nginx.service    # 重启nginx
上一篇下一篇

猜你喜欢

热点阅读