美文网首页
linux上编译nginx

linux上编译nginx

作者: bug_ling | 来源:发表于2020-01-02 22:53 被阅读0次

    1、确认以下库是否安装

    库:make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

    下载openssl、pcre、zlib库

    wget https://www.openssl.org/source/openssl-1.0.2u.tar.gz

    wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz

    wget https://zlib.net/zlib-1.2.11.tar.gz

    2、下载并解压

    wget http://nginx.org/download/nginx-1.17.7.tar.gz

    tar -zvxf nginx-1.17.7.tar.gz

    cd nginx-1.17.7/

    3、编译nginx

    ./configure --with-openssl=../openssl-1.0.2u --with-pcre=../pcre-8.43 --with-zlib=../zlib-1.2.11 --with-http_ssl_module --with-http_v2_module

    make && make install

    注意:编译的过程会出现以下错误:

    (1)configure: error: Invalid C++ compiler or C++ compiler flags

    (2)make[1]: *** [objs/Makefile:1314: ../pcre-8.43/Makefile] Error 1

    根据问题一,安装gcc-c++即可解决以上两个问题点

    4、创建软连接

    ln -s /usr/local/nginx/sbin/nginx  /usr/local/sbin/nginx

    nginx -v

    5、设置systemctl/service启动nginx服务

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

    [Unit]

    Description=nginx - high performance web server

    After=network.target remote-fs.target nss-lookup.target

    [Service]

    Type=forkingPIDFile=/var/run/nginx.pid

    ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

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

    reloadExecStop=/usr/local/nginx/sbin/nginx -s stop

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

    PrivateTmp=true

    [Install]

    WantedBy=multi-user.target

    将上面的代码复制到nginx.service中

    systemctl daemon-reload

    systemctl start/stop/reload/quit nginx.service

    systemctl enable nginx.service (设置开机自启)

    参开链接:

    https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#dependencies

    https://juejin.im/post/5d31ec3b5188253a8f27ef5b

    https://www.runoob.com/linux/nginx-install-setup.html

    https://blog.csdn.net/qq_17054659/article/details/77186249

    https://serverfault.com/questions/565339/nginx-fails-to-stop-and-nginx-pid-is-missing

    相关文章

      网友评论

          本文标题:linux上编译nginx

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