码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx

时间:2018-07-05 18:23:38      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:tab   代理   log   cat   main   str   域名   img   分享   

1.http服务器

2.虚拟主机

3.反向代理,负载均衡

 

安装nginx

配置虚拟主机:

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

一个server就是一个虚拟主机

1.通过端口访问

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
   server {
        listen       81;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

2.共用80端口,通过域名访问

server {
        listen       80;
        server_name  www.jd.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
   server {
        listen       80;
        server_name  www.taobao.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

  

 

反向代理:

启动两个tomcat:

upstream tomcat1 {
	server 192.168.25.148:8080;
    }
    server {
        listen       80;
        server_name  www.sina.com.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcat1;
            index  index.html index.htm;
        }
    }
    upstream tomcat2 {
	server 192.168.25.148:8081;
    }
    server {
        listen       80;
        server_name  www.sohu.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcat2;
            index  index.html index.htm;
        }
    }

  

负载均衡:

再启动一个tomcat,修改端口为8082,

访问www.sohu.com会轮询访问 weight=2的请求次数越多

    upstream tomcat2 {
	server 192.168.25.148:8081;
        server 192.168.25.148:8082 weight=2;
    }
    server {
        listen       80;
        server_name  www.sohu.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcat2;
            index  index.html index.htm;
        }
    }   

  

    server {

        listen       80;

        server_name  localhost;

 

        #charset koi8-r;

 

        #access_log  logs/host.access.log  main;

 
 

Htmlnginx安装目录下的html目录

 

 

 

技术分享图片        location / {

            root   html;

            index  index.html index.htm;

        }

    }

 

Nginx

标签:tab   代理   log   cat   main   str   域名   img   分享   

原文地址:https://www.cnblogs.com/zhoucx66/p/9269700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!