zoukankan      html  css  js  c++  java
  • Nginx配置基于端口号配置虚拟主机

    • 基于端口号配置虚拟主机的方式,是 Nginx 中配置虚拟主机最简单的方式,它的原理就是一个 Nginx 监昕多个端口 ,根据不同的端口号,来区分不同的网站。
    • 假设当前物理主机的 IP 为 106.13.19.188然后让其分别监听不同的端口,如 8001 和 8002 ,来实现根据不同端口号配置虚拟主机的功能。
    • 在配置虚拟主机前,首先打开 Nginx 的配置文件 nginx. conf,查看默认配置文件中 提供的关于虚拟主机配置的方法,具体如下。
    server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
    

    server 块中完成虚拟主机的设置,listen 命令监昕端口。
    因此,若要在 Nginx 中配置一个虚拟主机,只需在 http 块中添加一个 server 块即可 。 换句话说, http 块中的每个 server 块都是一个虚拟主机。

    • 修改 nginx. conf 配置文件,在 http 块中添加以下两个 server 配置。
    #配置量监听8001端口号的虚拟主机
    	server{
    		listen	8001;
    		server_name	106.13.19.188;
    		root html/html8001;
    		index index.jsp index.html index.htm;
    		
    	}
    
    #配置量监听8002端口号的虚拟主机
    	server{
    		listen	8002;
    		server_name	106.13.19.188;
    		root html/html8002;
    		index index.jsp index.html index.htm;
    		
    	}
    

    在上述配置中,监听 8001 端口的网站根目录设置为“html/html8001”,监昕 8002 端口 的网站根目录设置为“html/html8002”。 完成上述配置后 ,保存 nginx. conf 文件,平滑重启 Nginx 使设置生效。

    //切换到nginx目录重启配置文件
    cd /usr/local/nginx/sbin
    nginx -s reload
    
    • 编写测试文件并查看结果。
      首先 ,在/usr/ local/ nginx/html/下分别创建目录 html8001 和 html8002 o 然后 ,在不同 网站根目录下放置一个测试文件用于访问测试。
      ①在 html8001 目 录中创建 index. html 测试文件,编写内容如下 。
    <hl>11111</hl>
    

    ②在 html8002 目录中创建 index. html 测试文件,编写内容如下 。

    <hl>22222</hl>
    

    分别访问:
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    cscope的使用
    关于函数指针
    linux内核源码目录(转)
    lcc之内存分配
    符号管理之符号表
    监听UITextFiled文本发生改变
    Debugging Tools for Windows__from WDK7
    WinDBG__独立安装文件
    20160215
    QT Creator 代码自动补全
  • 原文地址:https://www.cnblogs.com/xdr630/p/15255077.html
Copyright © 2011-2022 走看看