nginx配置

nginx 命令有:

  nginx.exe -s stop|quit|reload|reopen

Windows下启动nginx用start nginx.exe。

 

nginx配置:

  upstream 用作负债均衡

  proxy_pass 用作反向代理,用法: proxy_pass http://host:port/uri/

例如:将本地环境下的两个项目test1、test2分别映射到test1.com、test2.com,test1和test2都在同一个8080端口的tomcat下面。

server {
       listen   80;
       server_name  test1.com;
       access_log logs/test1.com_access.log main;

        location / {
            proxy_redirect off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        REMOTE_ADDR     $remote_addr;
            proxy_set_header        HTTP_CLIENT_IP  $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            client_body_buffer_size 128k;
            proxy_connect_timeout   30;
            proxy_send_timeout      30;
            proxy_read_timeout      30;
            proxy_pass http://localhost:8080/test1/;      
        }
}

server {
       listen   80;
       server_name  test2.com;
       access_log logs/test2.com_access.log main;

        location / {
            proxy_redirect off;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        REMOTE_ADDR     $remote_addr;
            proxy_set_header        HTTP_CLIENT_IP  $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            client_body_buffer_size 128k;
            proxy_connect_timeout   30;
            proxy_send_timeout      30;
            proxy_read_timeout      30;
            proxy_pass http://localhost:8080/test2/;      
        }
}
View Code

 

 

 

 

 

 

 

相关资料:

1、Windows下Nginx的启动、停止等命令

2、Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解 

3、http://tengine.taobao.org/book/

4、https://www.ttlsa.com/nginx/use-nginx-proxy/

5、http://tshare365.com/archives/1617.html

 

posted @ 2016-04-19 15:56  xunux  阅读(223)  评论(0编辑  收藏  举报