计算机网络/计算机科学与应用/系统/运维/开发

多端口的虚拟主机

基于多端口虚拟主机

    # 第一个虚拟主机
    server {
        # 定义虚拟主机站点端口号 
        listen      81;
        # 填写虚拟主机的域名配置,没有域名可以写 localhost
        server_name  learn_nginx.com;
        # 给nginx定义网站的编码
        charset utf-8;
        # 针对虚拟主机 单独指定错误日志文件
        error_log logs/learn_nginx_error.log;
        # nginx的路径匹配规则
        # 如下的规则是最低级匹配,任何的nginx请求,都会进入location配置,会去定义的目录中寻找资料
        location / {
           # root关键词 是定义网页根目录,这个html是以nginx安装的路径为相对
           root   /www/vod;
           #  index关键词,定义nginx的首页文件名字,默认找index.html文件
           index  index.html index.htm;
        }
        # 设置nginx 状态页
        location /nginx_status {
           stub_status  on;
           access_log off;
        }
    }
    # 第二个虚拟主机
    server {
        listen       82;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   /www/www;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

重载Nginx服务:

systemctl resload nginx


浏览器访问:

http://192.168.1.216:81/

http://192.168.1.216:82


注意:需要在安全组中放开81和82端口


生活的强者,不是指能搞定一切困难,也不是指没有恐惧,而是就算心里藏着无尽的疲惫和委屈,还是会认真地做好手头上的事情;就算自己被生活锤得心灰意冷,还是会尽心尽力地负起责任;就算发现现实与理想的差距有十万里,虽然鞭长莫及,却依然马不停蹄。

评论

^