zoukankan      html  css  js  c++  java
  • 安装Nginx网络HTTP服务器(Linux) (2015-01-23)

    第一步:安装依赖库

    CentOS用这个

    yum install make gcc pcre-devel zlib-devel openssl-devel git bison wget

    Ubuntu用这个

    sudo apt-get install gcc libpcre++-dev libssl-dev make git

    第二步:下载所需nginx的扩展源码

    mkdir -p /home/git/code
    cd /home/git/code
    git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
    git clone https://github.com/agentzh/sregex
    git clone https://github.com/agentzh/replace-filter-nginx-module

    第三步:安装sregex

    cd /home/git/code/sregex
    make
    make install

    第四步:到www.nginx.org官方下载最新稳定版

    mkdir ~/down
    cd ~/down
    wget http://nginx.org/download/nginx-1.8.0.tar.gz
    tar zxvf nginx-1.6.2.tar.gz
    

    第五步:编译安装

    cd ~/down/nginx-1.6.2
    ./configure 
    --with-http_stub_status_module 
    --with-http_ssl_module 
    --with-http_spdy_module 
    --with-http_realip_module 
    --with-http_sub_module 
    --with-http_gzip_static_module 
    --with-ipv6 
    --add-module=/home/git/code/ngx_http_substitutions_filter_module 
    --add-module=/home/git/code/replace-filter-nginx-module

    执行编译安装

    make
    make install

     第六步:查看编译相关信息

    /usr/local/nginx/sbin/nginx -V

    如果看到下面的提示就对了

    nginx version: nginx/1.6.2
    built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
    TLS SNI support enabled
    configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-ipv6 --add-module=/home/git/ngx_http_substitutions_filter_module --add-module=/home/git/replace-filter-nginx-module

    第七步:启动与检查

    当你执行下面语句时,没有任何返回,说明运行成功。

    /usr/local/nginx/sbin/nginx

    确定是否运行成功

    netstat -anp |grep 80

    如果结果中存在

    tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      712/nginx

    说明成功了

    再来看看712/nginx的具体路径

    ps x |grep 712

    如果结果是

      712 ?        Ss     0:00 nginx: master process /usr/local/nginx/sbin/nginx

    可以看到路径/usr/local/nginx/sbin/nginx说明成功了

    最后将

    /usr/local/nginx/sbin/nginx

    写入到

    /etc/rc.local

    让系统开机就自动启动nginx

    最后说一些可能会出现的问题

    /usr/local/nginx/sbin/nginx: error while loading shared libraries: libsregex.so.0: cannot open shared object file: No such file or directory

    对于上面这种问题,可以用下面方法解决

    ldd /usr/local/nginx/sbin/nginx

    确定问题后,如果是32位系统执行

    ln -s /usr/local/lib/libsregex.so.0 /lib

     如果是64位系统,执行

    ln -s /usr/local/lib/libsregex.so.0 /lib64

    关于配置PHP方面的

    请编辑下面文件(推荐vi或vim)

    /usr/local/nginx/conf/nginx.conf

    1:找到下面一段文字,大概在65行(vi/vim编辑器的可以使用:65到达)

            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}

    将每一行前面的#符号都去掉

     2:将其中的

    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    改成

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    3:保存后,重新载入nginx配置文件

    /usr/local/nginx/sbin/nginx -t
    /usr/local/nginx/sbin/nginx -s reload

    4:创建phpinfo.php测试文件

    /usr/local/nginx/html/phpinfo.php

     内容为

    <?php
    phpinfo();

    5:运行php文件测试

    http://127.0.0.1/phpinfo.php

    请将127.0.0.1换成你服务器的IP地址,并在浏览器里打开查看。

    配置参考

    worker_processes 1;
    pid logs/nginx.pid;
    events{
        worker_connections 1024;
    }
    http{
        access_log off;
        include mime.types;
        sendfile on;
        client_body_temp_path temp/client_body_temp;
        fastcgi_temp_path temp/fastcgi_temp;
        scgi_temp_path temp/scgi_temp;
        uwsgi_temp_path temp/uwsgi_temp;
        proxy_temp_path temp/proxy_temp;
        server{
            listen 0.0.0.0:80;
            server_name www.baidu.com;
            proxy_set_header Host www.baidu.com;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            location / {
                proxy_pass http://www.baidu.com;
            }
        }
        server{
            listen 0.0.0.0:80 default;
            root html;
        }
    }
    飞儿传媒www.firadio.com
  • 相关阅读:
    【2020-05-17】人生十三信条
    【2020-05-16】评价与骄傲
    【2020-05-15】每天都充满向上的激情
    【04NOIP普及组】火星人(信息学奥赛一本通 1929)(洛谷 1088)
    next_permutation(全排列算法)
    【03NOIP普及组】麦森数(信息学奥赛一本通 1925)(洛谷 1045)
    快速幂
    【03NOIP普及组】栈(信息学奥赛一本通 1924)(洛谷 1044)
    【06NOIP普及组】数列(信息学奥赛一本通 1937)(洛谷 1062)
    【00NOIP普及组】计算器的改良(信息学奥赛一本通 1910)(洛谷 1022)
  • 原文地址:https://www.cnblogs.com/firadio/p/4111823.html
Copyright © 2011-2022 走看看