zoukankan      html  css  js  c++  java
  • Nginx 虚拟主机配置

    Nginx 虚拟主机配置

    1、主配置文件下加入虚拟主机参数。
    vim nginx.conf
    
    include vhosts/*.conf;
    配置文件

    2、创建虚拟主机目录,文件。

    mkdir /usr/local/nginx/conf/vhosts
    创建虚拟主机目录
    touch /usr/local/nginx/conf/vhosts/nginx_vhosts1.conf
    touch /usr/local/nginx/conf/vhosts/nginx_vhosts2.conf
    touch /usr/local/nginx/conf/vhosts/nginx_vhosts3.conf
    创建虚拟主机文件

    基于IP

    1、添加IP地址。

    ifconfig eth0:1 192.168.1.131
    ifconfig eth0:2 192.168.1.132
    ifconfig eth0:3 192.168.1.133
    

    2、修改虚拟主机文件。

    # 基于IP 主机1
    server{
       # 监听端口
       listen 192.168.1.131:80;
       # 访问域名
       server_name www.xxx.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url1;
    }
    修改虚拟主机1
    # 基于IP 主机2
    server{
       # 监听端口
       listen 192.168.1.132:80;
       # 访问域名
       server_name www.xxx.com;
       # 网页索引类型
       index index.html index.htm index.php;
       # 指定URL资源
       root /usr/local/url2;
    }
    修改虚拟主机2
    # 基于IP 主机3
    server{
       # 监听端口
       listen 192.168.1.133:80;
       # 访问域名
       server_name www.xxx.com;
       # 网页索引类型
       index index.html index.htm index.php;
       # 指定URL资源
       root /usr/local/url3;
    }
    修改虚拟主机3

    基于域名

    1、修改hosts文件,或使用DNS解析。

    C:WindowsSystem32driversetc
    
    192.168.1.115 www.131.com www.132.com www.133.com
    修改hosts文件

     2、修改虚拟主机文件。

    # 基于域名 主机1
    server{
       # 监听端口
       listen 80;
       # 访问域名
       server_name www.131.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url1;
    }
    修改虚拟主机1
    # 基于域名 主机2
    server{
       # 监听端口
       listen 80;
       # 访问域名
       server_name www.132.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url2;
    }
    修改虚拟主机2
    # 基于域名  主机3
    server{
       # 监听端口
       listen 80;
       # 访问域名
       server_name www.133.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url3;
    }
    修改虚拟主机3

    基于端口

     1、修改虚拟主机文件。

    # 基于端口 主机1
    server{
       # 监听端口
       listen 80;
       # 访问域名
       server_name www.xxx.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url1;
    }
    修改虚拟主机1
    # 基于端口 主机2
    server{
       # 监听端口
       listen 8080;
       # 访问域名
       server_name www.xxx.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url2;
    }
    修改虚拟主机2
    # 基于端口 主机3
    server{
       # 监听端口
       listen 8090;
       # 访问域名
       server_name www.xxx.com;
       # 网页索引类型
       index index.html index.htm;
       # 指定URL资源
       root /usr/local/url3;
    }
    修改虚拟主机3

    注意事项

    1、加载php文件需要使用如下参数:

    # 使用php类型
    location ~ .php$ {
      include fastcgi_params;
            # TCP:127...:9000、也可以使用socket
      fastcgi_pass 127.0.0.1:9000;
            # 设置类型索引
      fastcgi_index index.php;
            # URL资源路径
      fastcgi_param SCRIPT_FILENAME /usr/local/url$fastcgi_script_name;
    }
    虚拟主机文件内

  • 相关阅读:
    (转)一文讲清TCP/IP 协议
    Java框架之Spring Boot和Spring Cloud区别
    php大力力 [006节]初步接触认识phpMyAdmin
    php大力力 [005节] php大力力简单计算器001
    php大力力 [004节]PHP常量MAMP环境下加载网页
    php大力力 [003节]php在百度文库的几个基础教程mac环境下文本编辑工具
    php大力力 [002节]mac php环境安装,mamp安装 ,phpMyAdmin启动
    php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28
    C# DataSet与DataTable的区别和用法 ---转载
    【SqlServer】利用sql语句附加,分离数据库-----转载
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/8393804.html
Copyright © 2011-2022 走看看