centos7 手动安装nginx

  1. 添加nginx用户组及用户

    groupadd nginx
    useradd nginx -g nginx
    
  2. nginx使用C语言开发,在安装之前,需要先安装一些一些工具库
    gcc-c++:nginx的源码编译需要该环境
    pcre:Perl Compatible Regular Expressions,一个Perl库,可以解析正则表达,nginx中的http模块依赖此进行正则表达式的解析
    pcre-devel:是pcre的一个二次元开发库
    zlib:nginx需要依赖此库对http内容进行gzip
    openssl:是一个安全套接字密码库,包括密码算法,证书,SSL协议等,而nginx支持http,https,而https是在ssl协议上传输的

  3. 安装以上的工具或类库

    yum install gcc-c++
    yum install -y pcre pcre-devel
    yum install -y zlib zlib-devel
    yum install -y openssl openssl-devel
    
    
  4. 下载nginx

    cd /usr/software/
    wget -c https://nginx.org/download/nginx-1.15.2.tar.gz
    
    
  5. 解压并移动位置

    tar -zxvf nginx-1.15.2.tar.gz
    mv nginx-1.15.2 /usr/nginx
    
    
  6. 编译安装

    cd /usr/nginx
    # 如果需要去除Http头信息,加上  --add-module=/root/software/headers-more-nginx-module-v0.33
    # 插件地址: https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz
    ./configure  --with-http_stub_status_module --with-http_ssl_module --add-module=/root/software/headers-more-nginx-module-v0.33
    

    这里写图片描述

    注意:查看上面图片中的文件夹,如果不存在,最好手动创建一下,以免在安装时出现什么错误

    mkdir /var/temp
    mkdir /var/temp/nginx
    mkdir /var/run/nginx/
    
    make && make install
    
    cd /usr/local/nginx/
    

    查看在/usr/local/nginx中存在conf,html等

  7. nginx一些命令

    进入安装目录:cd /usr/local/nginx/sbin/
    启动:./nginx,如果报nginx.pid no such file or directory,则需要在/var/run/nginx文件夹
    指定nginx配置文件:./nginx -c /usr/local/nginx/conf/nginx.conf
    停止:./nginx -s quit
    重新加载:./nginx -s reload 或者 先停止再重启
    
  8. 验证
    启动nginx,访问ip地址,如果出现welcome to nginx,则代表成功
    这里写图片描述

  9. 如果有需要处理防火墙

    关闭防火墙: systemctl stop firewalld.service
    开启防火墙: systemctl start firewalld.service
    关闭开机启动: systemctl disable firewalld.service
    开启开机启动: systemctl enable firewalld.service
    
    
  10. 如果使用阿里云服务器,有个地方一定要注意,就是服务器实例的安全组一定要配置,将80端口配置进去,不然无法访问
    在这里插入图片描述

  11. 开机启动

    vi /etc/systemd/system/nginx.service
    复制粘贴以下内容:
    [Unit]
    Description=nginx-server
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx  -c   /usr/local/nginx/conf/nginx.conf
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    然后:
    [root@localhost bin]# systemctl daemon-reload
    
    [root@localhost bin]# systemctl start nginx.service
    
    [root@localhost bin]# systemctl enable nginx.service
    
  12. 添加软连接

    ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
    
  13. 开放防火墙

    firewall-cmd --zone=public --add-service=http --permanent
    firewall-cmd --zone=public --add-port=80/tcp --permanent
    
    firewall-cmd  --reload
    firewall-cmd  --list-ports
    firewall-cmd  --list-service
    
    # 指定端口
    firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值