centos7 安装nginx 完整步骤

1.安装gcc gcc是用来编译下载下来的nginx源码

yum install gcc-c++
2、安装pcre和pcre-devel
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。
nginx 的 http 模块使用 pcre 来解析正则表达式,pcre-devel 是使用 pcre 开发的一个二次开发库。
yum install -y pcre pcre-devel

3、安装zlib zlib提供了很多压缩和解方式,nginx需要zlib对http进行gzip
yum install -y zlib zlib-devel

4、安装openssl openssl是一个安全套接字层密码库,nginx要支持https,需要使用openssl
yum install -y openssl openssl-devel

  1. 下载nginx
    wget http://nginx.org/download/nginx-1.14.0.tar.gz

6.解压
tar -zxvf nginx-1.14.0.tar.gz

  1. cd到文件路劲

8.编译
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module

9.安装
make && make install

10.启动
nginx -c /etc/nginx/nginx.conf

  1. 如果出现[emerg] getpwnam(“nginx”) failed 错误 执行
    useradd -s /sbin/nologin -M nginx
    id nginx

12.如果出现 [emerg] mkdir() “/var/temp/nginx/client” failed (2: No such file or directory) 错误 执行
sudo mkdir -p /var/tem/nginx/client

13.如果您正在运行防火墙,请运行以下命令以允许HTTP和HTTPS通信:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

#########################################

停止nginx:
#./nginx -s stop

重启nginx(配置文件变动后需要重启才能生效):
#./nginx -s reload

检查配置文件是否正确:
#./nginx -t

查看nginx的pid:
cat /usr/local/nginx/logs/nginx.pid

查看nginx版本
$ ./nginx -v

回头看编译配置
#./nginx -V

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值