nginx 的安装与反向代理

一、nginx的安装:

 1、进入指定目录:

[root@iZuf6fvqqwb30ocs6eb3a7Z /]#  cd /usr/local/src
[root@iZuf6fvqqwb30ocs6eb3a7Z src]# 

2、下载,解压

[root@localhost src]# wget http://nginx.org/download/nginx-1.11.10.tar.gz
[root@localhost src]# tar -zxvf nginx-1.11.10.tar.gz

3、启用nginx功能:

[root@localhost src]# ./configure  --prefix=/usr/local/nginx --with-stream 

4、然后make,make install

[root@localhost src]# make
[root@localhost src]# make install

5、如果在第3步发现有报错:

    ./configure:  error: the HTTP rewrite module requires the PCRE library.

     安装pcre-devel解决问题:

    yum install pcre-devel

   

   再次执行第3步,如果有报错:

   error: the HTTP gzip module requires the zlib library.

   安装这个zlib库就可以了。

   解决办法:

    yum install zlib-devel

 

    编译SSL模块,安装openssl :

      cd /usr/local/src
      wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
      tar -zxvf openssl-1.0.1c.tar.gz
      cd openssl-1.0.1c
      ./Configure && make && make install
      进入nginx目录nginx-1.11.10
      ./configure --prefix=/usr/local/nginx --with-stream  --with-openssl=/usr/local/src/openssl-1.0.1c --with-http_ssl_module(如要安装ssl执行这句,参考https://zhangge.net/4856.html)

    

  再执行第4步,make,make install.......安装成功 

 

二、测试nginx是否安装成功

     查找nginx进程号:ps -ef | grep nginx,

     nginx启动:/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

     nginx重启:进入cd /usr/local/nginx/sbin/目录》》》./nginx -s reload

     快速停止nginx : kill -QUIT 第二个数字

    PS:启动ngin后,在浏览器地址栏输入服务器ip,如果能看到nginx页面则安装成功!

 

三、请求转发:

    进入目录:

[root@iZuf6fvqqwb30ocs6eb3a7Z nginx]# cd /usr/local/nginx/
[root@iZuf6fvqqwb30ocs6eb3a7Z nginx]# ls
client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp
[root@iZuf6fvqqwb30ocs6eb3a7Z nginx]# 

 

 可以看到进入nginx目录后,有conf这个目录,进入这个目录:  

 

[root@iZuf6fvqqwb30ocs6eb3a7Z conf]# ls
fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf
fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default
[root@iZuf6fvqqwb30ocs6eb3a7Z conf]# 

 可以有个nginx.conf这个文件,发开他,修改里面的配置:

   

 server {
        listen       8081;
        server_name  localhost;
        location / {
                proxy_pass http://localhost:5555/best/health;
                client_max_body_size  1000m;
        }

  

保存后退出,重启nginx,测试请求,会发现凡是来自这台服务器8081的请求都被转发到5555上去了。

 

posted @ 2017-11-17 11:11  wanglittlehandsome  阅读(222)  评论(0编辑  收藏  举报