美文网首页
Nginx安装

Nginx安装

作者: 大厂offer | 来源:发表于2018-08-23 17:54 被阅读19次

    一、环境

    操作系统:CentOS Linux release 7.3.1611 (Core)
    nginx版本:nginx-1.14.0
    其他依赖(下载地址见文末): openssl-1.1.1-pre9.tar.gz pcre-8.38.tar.gz zlib-1.2.11.gz
    文件结构:在/opt/nginx文件夹下使用指令tree -f -L 1

    nginx
    ├── nginx/nginx-1.14.0
    ├── nginx/openssl-1.1.1-pre9
    ├── nginx/openssl-1.1.1-pre9.tar.gz
    ├── nginx/pcre-8.38
    ├── nginx/pcre-8.38.tar.gz
    ├── nginx/zlib-1.2.11
    └── nginx/zlib-1.2.11.gz
    

    二、预安装

    安装系统自带依赖:

    [root@ch-nginx ~] yum install -y gcc gcc-c++
    [root@ch-nginx ~] yum install pcre-devel.x86-64
    [root@ch-nginx ~] yum install zlib-devel.x86-64
    [root@ch-nginx ~] yum install openssl-devel.x86-64
    

    创建相应目录:

    [root@ch-nginx ~] mkdir /usr/local/pcre
    [root@ch-nginx ~] mkdir /usr/local/openssl
    [root@ch-nginx ~] mkdir /usr/local/zlib
    [root@ch-nginx ~] mkdir /usr/local/nginx
    

    三、安装

    1.安装pcre

    [root@ch-nginx ~] cd /opt/nginx/pcre-8.38
    [root@ch-nginx pcre-8.38] ./configure --prefix=/usr/local/pcre
    [root@ch-nginx pcre-8.38] make && make install
    

    2.安装openssl

    [root@ch-nginx ~] cd /opt/nginx/openssl-1.1.1-pre9
    [root@ch-nginx openssl-1.1.1-pre9] ./config --prefix=/usr/local/openssl
    [root@ch-nginx openssl-1.1.1-pre9] make && make install
    

    3.安装zlib

    [root@ch-nginx ~] cd /opt/nginx/zlib-1.2.11
    [root@ch-nginx zlib-1.2.11] ./configure --prefix=/usr/local/zlib
    [root@ch-nginx zlib-1.2.11] make && make install
    

    4.安装nginx

    [root@ch-nginx ~] cd /opt/nginx/nginx-1.14.0
    [root@ch-nginx nginx-1.14.0] ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-zlib=/opt/nginx/zlib-1.2.11 --with-openssl=/opt/nginx/openssl-1.1.1-pre9 --with-stream 
    [root@ch-nginx nginx-1.14.0] make && make install
    

    ./configure --prefix=/usr/local/nginx表示安装到/usr/local/nginx目录下面

    5.启动nginx

    [root@ch-nginx nginx-1.14.0] /usr/local/nginx/sbin/nginx
    

    6.检查nginx是否安装成功

    [root@ch-nginx ~]# ps -ef|grep nginx
    root     22596     1  0 17:24 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
    nobody   22616 22596  0 17:27 ?        00:00:00 nginx: worker process
    root     22685   874  0 17:55 pts/0    00:00:00 grep --color=auto nginx
    

    7. 开启80端口

    停止防火墙
    [root@ch-nginx ~] service iptables stop
    或是把 80 端口加入到的排除列表:
    [root@ch-nginx ~] iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    [root@ch-nginx ~] service iptables save
    [root@ch-nginx ~] service iptables restart
    

    四、nginx相关指令

    • 启动:/usr/local/nginx/sbin/nginx
    • 检查 Nginx 是否启动并监听了 80 端口:netstat -ntulp | grep 80
    • 检查 Nginx 启用的配置文件是哪个:/usr/local/nginx/sbin/nginx -t
    • 刷新 Nginx 配置后重启:/usr/local/nginx/sbin/nginx -s reload
    • 停止 Nginx:/usr/local/nginx/sbin/nginx -s stop

    相关依赖下载地址:
    nginx: http://nginx.org/download/nginx-1.14.0.tar.gz
    pcre-8.38: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
    openssl: https://www.openssl.org/source/openssl-1.1.1-pre9.tar.gz
    zlib: http://www.zlib.net/zlib-1.2.11.tar.gz

    相关文章

      网友评论

          本文标题:Nginx安装

          本文链接:https://www.haomeiwen.com/subject/ekpmiftx.html