zoukankan      html  css  js  c++  java
  • centos7.2 安装 nginx

    Centos 7 源码编译安装 Nginx 1.13

    原文地址:https://renwole.com/archives/39


    1.先决条件:

    centos7.2 64位,安装配置nginx前必须安装nginx依赖包,并安装前文开头所提供的依赖包。此依赖组件包适用于Nginx任意版本。

    安装依赖组件(包含Nginx依赖):

    $ yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel

        新建web用户和组
        $ /usr/sbin/groupadd www
        $ /usr/sbin/useradd -g www www
        $ ulimit -SHn 65535 //设置linux高负载参数

    2.从官方下载Nginx以及OpenSSL

    下载Nginx时有两个版本:开发版和稳定版,如果用于生产就下载稳定版本,http://nginx.org/en/download.html (最好下载最新版本的稳定版,这样会有bug修复以及新特性)我下载的是就是目前最新版本nginx-1.13.9。

        $ cd /tmp
        $ wget https://www.openssl.org/source/openssl-1.1.1-pre2.tar.gz
        $ tar zxvf openssl-1.1.1-pre2.tar.gz
        $ wget https://nginx.org/download/nginx-1.13.5.tar.gz
        $ tar zxvf nginx-1.13.9.tar.gz
        $ cd nginx-1.13.9

    3.安装Nginx

        你可能会注意到有些文档教程安装nginx的时候,并未指派这么多模块,(看起来好长),有的连模块和用户都没有指派,其实模块是根据自己的需要指派的, 如果想以后不麻烦,那么就按照下面的模块指派就行了,其实这也算是全能的了,不然后期你需要什么还得重新编译进去,不是很麻烦,但也不省事。至于是否指派用户组,我坚决会让你指派,这可关乎nginx配置的可用性和安全稳定。

        $ ./configure
        --prefix=/usr/local/nginx
        --user=www
        --group=www
        --with-pcre
        --with-openssl=/tmp/openssl-1.1.0e
        --with-http_ssl_module
        --with-http_v2_module
        --with-http_realip_module
        --with-http_addition_module
        --with-http_sub_module
        --with-http_dav_module
        --with-http_flv_module
        --with-http_mp4_module
        --with-http_gunzip_module
        --with-http_gzip_static_module
        --with-http_random_index_module
        --with-http_secure_link_module
        --with-http_stub_status_module
        --with-http_auth_request_module
        --with-http_image_filter_module
        --with-http_slice_module
        --with-mail
        --with-threads
        --with-file-aio
        --with-stream
        --with-mail_ssl_module
        --with-stream_ssl_module

        $ make -j8 && make install //编译并安装

    4.创建 systemctl 系统 Nginx 单元文件

        安装完成后还需要开机自启动,不然每次开机都需要手动,那岂不是太麻烦。

        $ vim /usr/lib/systemd/system/nginx.service

        [Unit]
        Description=The nginx HTTP and reverse proxy server
        After=syslog.target network.target remote-fs.target nss-lookup.target

        [Service]
        Type=forking
        PIDFile=/usr/local/nginx/logs/nginx.pid
        ExecStartPre=/usr/local/nginx/sbin/nginx -t
        ExecStart=/usr/local/nginx/sbin/nginx
        ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid
        ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid
        PrivateTmp=true

        [Install]
        WantedBy=multi-user.target

        保存并退出。

    5.加入开机自启动并启动Nginx

        $ systemctl enable nginx.service
        $ systemctl restart nginx.service

    6.设置Firewalld防火墙

        $ firewall-cmd --zone=public --add-port=80/tcp --permanent
        $ firewall-cmd --reload

    7.查看Nginx是否启动成功

        $ ss -ntlp

    8.配置nginx支持php
    配置nginx.conf如下:

    其中:fastcgi_pass的.sock路径在/usr/local/php/etc/php-fpm.d/www.conf中搜索listen
     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ .php$ {
                root           html;
                #fastcgi_pass   127.0.0.1:9000;
                fastcgi_pass   unix:/var/run/www/php-cgi.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }

  • 相关阅读:
    bzoj1415 NOI2005聪聪和可可
    Tyvj1952 Easy
    poj2096 Collecting Bugs
    COGS 1489玩纸牌
    COGS1487 麻球繁衍
    cf 261B.Maxim and Restaurant
    cf 223B.Two Strings
    cf 609E.Minimum spanning tree for each edge
    cf 187B.AlgoRace
    cf 760B.Frodo and pillows
  • 原文地址:https://www.cnblogs.com/deverz/p/8533025.html
Copyright © 2011-2022 走看看