nginx 安装及配置

1.安装gzip, 到http://www.zlib.net/ 下载gzip包,然后依次执行:

  tar -zxvf gzipXXX.tar.gz

  ./configure

  make

  make install

 

2.安装pcre包,到http://www.pcre.org/下载pcre包,然后依次执行:

  tar -zxvf pcreXXX.tar.gz

  ./configure

  make

  make intall

 

3.安装nginx, 下载源文件包,然后依次执行:

 tar -zxvf nginx.XXX.tar.gz

   ./configure

   make

   make install

 

4.nginx将被安装在 /usr/local/nginx中,打开 /usr/local/nginx/conf/nginx.conf,进行配置:

  server{
        listen       80;
        server_name    guoshanji.com;
        location / {
            proxy_pass http://localhost:8083;
            index index.html;
        }
    }

    server {
        listen       80;
        server_name  kevin.guoshanji.com;
        location / {
            proxy_pass http://localhost:8080;
            index index.html;
        }
    }

5.到 /usr/local/nginx/sbin/目录下执行如下命令:

 ./nginx -t  (测试配置是否正确)

   ./nginx    (启动nginx)

   ./nginx -s reload (重新启动,生配置文件生效)

   ./nginx -s stop (停止nginx)

 

注:如果启动报如下错误:

./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

执行如下命令:

32位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib
64位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib64

 

备注2:

如果需要转发url,可进行如下配置,配置后请求url地址会被转发,但最后显示在地址栏的url会改变。

    server {

        listen       80;

        server_name  localhost;

 

location / {
         rewrite ^(.*)$ http://localhost:8080/distribute/distribute/execute.do?$request_uri? break;
        }        

location /favicon.ico{

        }

    }

 

备注3:

转发请求到不同的服务器,并认状态,nginx.conf配置如下:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;


    server {
        listen       80;
        server_name  localhost;
      


         
location / {

     if ($http_cookie ~* "website=old"){
     
     proxy_pass http://10.1.14.253:80;
     
     break;
         
         }
         if ($http_cookie ~* "website=new"){
         
         proxy_pass http://10.1.14.253:81;
         break;
         }
         
         
         proxy_pass http://localhost:8080;
         break;

        }
               
        
location /favicon.ico{
        }
    }

}

注意需要将后端10.1.14.253:80,10.1.14.253:81的cookie写到客户端,下次请求时,将自动处于登录状态。

 

根据pc浏览器或手机浏览器跳转到不同网站:

        location / {

       if ( $http_user_agent ~* "Mobile" ){

           proxy_pass   http://s.glocalme.com;

       }

       proxy_pass   http://en.glocalme.com;

       

 

     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值