nginx 安装

tar –zxvf nginx-1.10.3.tar.gz

cd nginx-1.10.3

./configure --prefix=/usr/local/nginx

若提示没有C编译环境,由于新安装的Centos7没有安装编译C的环境,需要先进行编译环境安装。

yum install gcc gcc-c++ kernel-devel

./configure --prefix=/usr/local/nginx--with-http_ssl_module

此时若提示error: the HTTP rewrite module requires the PCRE library.

安装yum -y install pcre-devel

./configure --prefix=/usr/local/nginx

此时若提示error: the HTTP gzip module requires the zlib library.

安装yum install -y zlib-devel

./configure --prefix=/usr/local/nginx--with-http_ssl_module

make                           (如果需要支持ipv6增加--with-ipv6编译出现警告错误在上面加上--with-cc-opt="-Wno-error"

如果提示SSL modules require the OpenSSL library.

yum -y install openssl openssl-devel

make install

编辑 vi nginx.conf 修改相关代理配置

之后保存配置变更:./nginx –s reload

如果报如果报nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed,执行:

./nginx -c /usr/local/nginx/conf/nginx.conf

修改完成配置,配置防火墙允许80端口访问。

systemctl start firewalld

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

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone= public --query-port=80/tcp

删除

firewall-cmd --zone= public --remove-port=80/tcp –permanent

配置systemd:

vim /usr/lib/systemd/system/nginx.service:

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

Restart=always

RestartSec=10s

[Install]

WantedBy=multi-user.target

开机自启动:

systemctl daemon-reload

systemctl enable nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值