Nginx在Linux下的安装部署

Nginx简单介绍

          Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 server,也是一个 IMAP/POP3/SMTP serverNginx作为负载均衡server:Nginx 既能够在内部直接支持 Rails 和 PHP 程序对外进行服务。也能够支持作为 HTTP代理server对外进行服务。

nginx站点国内的用户有:百度、新浪、网易、腾讯等等。


长处:高并发(10万并发)。部署简单。内存消耗小,成本低。

缺点:rewrite功能不够强大。模块没Apache多。


Nginx的安装

       下载Nginx(http://nginx.org/en/download.html)。最新的好像是nginx-1.9.3


       下载:wget  http://nginx.org/download/nginx-1.9.3.tar.gz

        

        安装:在安装前安装ngxin所需的模块,以及编译c,c++的软件


                   yum install gcc-c++

         yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

       

        在Ubuntu下使用例如以下:

           sudo apt-get install libssl-dev
           sudo apt-get install libpcre3 libpcre3-dev

   下载nginx的第三方模块,动静分离proxy_cache做缓存,下载网址下载最新的文件,和nginx的下包放在一起(http://labs.frickle.com/files/

        

         wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz ./


   解压:比方文件下载在/home/andy/文件夹下


        tar xzvf nginx-1.9.3.tar.gz

        cd nginx-1.9.3


   安装Nginx所需的模块

        # nginx -V              //能够看到原来的编译选项,以下用到
        # ./configure ... --add-module=..       //你的第三方模块

        

        ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --without-http-cache --add-module=../ngx_cache_purge-2.3


      

      

         编译安装


                 make //make后不要install,改用手动拷贝。

先备份

                 make install

       

      安装完毕后在/usr/local/会多nginx文件夹,然后

cd /usr/local/nginx

       

        启动Nginx


                 cd sbin

                ./nginx


        又一次启动


                 cd sbin

                ./nginx -s reload

    

       卸载方法

         # 删除nginx,保留配置文件
          apt-get remove nginx
         #删除配置文件
         rm -rf /home/nginx


 安装出现的问题

       假设启动时出现例如以下问题时

             1:port被占用

                

                 说明:80port已被占用


                 netstat -anp | grep 80   查询占用80port的进程


                杀死该进程


                kill  -s 9  pid(进程id)

        

              2:错误为:./configure: error: the HTTP rewrite module requires thePCRE library.

                        解决的方法:安装pcre-devel模块


                           yum -y install pcre-devel


      3.Ubuntu下用apt-get 取代全部的yum

     (配置VMwareUbuntu下的静态ip:

          1 将虚拟的网络连接设置为桥接模式

          2 sudo ifconfig eth0 192.168.1.155 netmask 255.255.255.0

     

      4.缺少安装的OpenSSL库

   make: *** No rule to make target `build', needed by `default'.  Stop.
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
 
 
     ubuntu下解决的方法:
      apt-get install openssl
      apt-get install libssl-dev
 
     centos下解决的方法:
       yum -y install openssl openssl-devel


      安装完毕。

原文地址:https://www.cnblogs.com/mthoutai/p/6867032.html