美文网首页
nginx通过端口区分不同虚拟机<2>

nginx通过端口区分不同虚拟机<2>

作者: 天空在微笑 | 来源:发表于2017-11-12 21:56 被阅读17次
    1. 通过端口区分不同虚拟机
      Nginx的配置文件:
      /usr/local/nginx/conf/nginx.conf
    | 
    
    #user  nobody;
    
    worker_processes  1;
    
    #error_log  logs/error.log;
    
    #error_log  logs/error.log  notice;
    
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    events {
    
        worker_connections  1024;
    
    }
    
    http {
    
        include       mime.types;
    
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    
        #                  '$status $body_bytes_sent "$http_referer" '
    
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
    
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
    #一个server节点就是一个虚拟主机
    
        server {
    
            listen       80;
    
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
    
    
            location / {
                #Html是nginx安装目录下的html目录
                root   html;
    
                index  index.html index.htm;
    
            }
    
        }
    
    }
    
    

    可以配置多个server,配置了多个虚拟主机。

    
    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
        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-81;
                index  index.html index.htm;
            }
        }
    }
    

    重新加载配置文件
    [root@localhost nginx]# sbin/nginx -s reload
    用sublineText在windows上编辑远程Linux文件
    复制一份html目录并改名为html-81

    cp -r html html-81

    重新加载nginx配置文件

    sbin/nginx -s reload

    最后在浏览器中通过不同端口可以访问到不同的网站

    相关文章

      网友评论

          本文标题:nginx通过端口区分不同虚拟机<2>

          本文链接:https://www.haomeiwen.com/subject/odqomxtx.html