• Nginx安装


    目录

    1. 安装必要环境

    1.1 需要安装gcc环境

    1.2 PERE

    1.3 zlib

    1.4 openssl

    2. 安装nginx

    2.1 下载和解压

    2.2 编译

    2.2.1 设定配置

     2.2.2 编译

    2.2.3 安装

    3. 启动nginx

    4. 配置环境变量

     5. 加入system管理


    1. 下载Nginx

    1. 安装必要环境

    1.1 需要安装gcc环境

    yum install gcc-c++

    1.2 PERE

    PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。

    yum install -y pcre pcre-devel

    1.3 zlib

    zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

    yum install -y zlib zlib-devel

    1.4 openssl

    OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

    yum install -y openssl openssl-devel

    2. 安装nginx

    2.1 下载和解压

     地址:nginx: download

    选择stable版本,linux服务器选择nginx-1.22.1

    在服务器上用wget直接下载:

    1. cd /usr/local 
    2. wget http://nginx.org/download/nginx-1.22.1.tar.gz

    解压

    tar -xf nginx-1.22.1.tar.gz

    2.2 编译

    2.2.1 设定配置

    进入目录查看配置选项

    1. cd nginx-1.22.1
    2. ./configure --help

    这里选择如下配置:

    1. ./configure \
    2. --prefix=/usr/local/nginx \
    3. --pid-path=/var/run/nginx/nginx.pid \
    4. --lock-path=/var/lock/nginx.lock \
    5. --error-log-path=/var/log/nginx/error.log \
    6. --http-log-path=/var/log/nginx/access.log \
    7. --with-http_gzip_static_module \
    8. --http-client-body-temp-path=/var/temp/nginx/client \
    9. --http-proxy-temp-path=/var/temp/nginx/proxy \
    10. --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
    11. --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
    12. --http-scgi-temp-path=/var/temp/nginx/scgi \
    13. --with-http_stub_status_module \
    14. --with-http_ssl_module \
    15. --with-file-aio \
    16. --with-http_realip_module

    创建临时目录

    mkdir /var/temp/nginx -p

     2.2.2 编译

    在nginx-1.22.1目录下,执行make

    make

    2.2.3 安装

    在nginx-1.22.1目录下,执行make install

    make install

    进入安装目录查看:

    1. cd /usr/local/nginx
    2. ll

     其中html是里面首页html文件。conf里面是配置文件。sbin里面只执行文件。

    3. 启动nginx

    进入sbin,执行命令:./nginx

    1. cd /usr/local/nginx/sbin
    2. ./nginx

    查看nginx是否启动

    ps -aux | grep nginx

    4. 配置环境变量

    编辑/etc/profile:

    vi /etc/profile

    新增nginx的路径

    export PATH=$PATH:$MAVEN_HOME/bin:/usr/local/nginx/sbin

    生效文件

    source /etc/profile

     5. 加入system管理

    执行命令:

    vi /usr/lib/systemd/system/nginx.service

    输入内容:

    1. [Unit]
    2. Description=nginx - high performance web server
    3. Documentation=http://nginx.org/en/docs/
    4. After=network-online.target remote-fs.target nss-lookup.target
    5. Wants=network-online.target
    6. [Service]
    7. Type=forking
    8. PIDFile=/usr/local/nginx/logs/nginx.pid
    9. ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    10. ExecReload=/usr/local/nginx/sbin/nginx -s reload
    11. ExecStop=/usr/local/nginx/sbin/nginx -s stop
    12. [Install]
    13. WantedBy=multi-user.target

    重启

    1. systemctl daemon-reload
    2. systemctl start nginx

  • 相关阅读:
    关于针对XSS漏洞攻击防范的一些思考
    「滚雪球学Java」:方法函数(章节汇总)
    【书城项目】第二阶段-用户注册和登陆
    react写倒计时
    使用VSCode插件开发Hyperledger Fabric智能合约(链码)
    【mediasoup-sfu-cpp】5: SfuDemo:分发ok
    Windows上运行Redis
    C#获取声音信号并通过FFT得到声音频谱
    第2-4-7章 docker安装WorkBench-规则引擎Drools-业务规则管理系统-组件化-中台
    基于JAVA航帆学院网站计算机毕业设计源码+数据库+lw文档+系统+部署
  • 原文地址:https://blog.csdn.net/hubin0011/article/details/128130476