Nginx下,一个server标签就是一个虚拟主机。

1、基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站

2、基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的管理后台

3、基于ip的虚拟主机,几乎不用。

基于域名配置虚拟主机步骤:

需要建立/data/www /data/bbs目录,windows本地hosts添加虚拟机ip地址对应的域名解析;对应域名网站目录下新增index.html文件;

nginx.conf配置文件新增如下代码:

server {

listen 80;

server_name www.linuxidc.com;

index index.html;

root /data/www;

}

server {

listen 80;

server_name bbs.linuxidc.com;

index index.html;

root /data/bbs;

}

验证结果,使用curl测试,或者浏览器输入域名访问;

# curl -xlocalhost:80 www.linuxidc.com

this is linuxidc linux

# curl -xlocalhost:80 bbs.linuxidc.com

this is linuxidc bbs

基于端口的虚拟主机配置:

使用端口来区分,浏览器使用域名或ip地址:端口号 访问;

server

{

listen 8000;

server_name www.linuxidc.com;

root /data/www;

}

server

{

listen 8001;

server_name www.linuxidc.com;

root /data/bbs;

}

验证结果,使用curl测试,或者浏览器输入域名访问;

# curl www.linuxidc.com:8000

this is linuxidc linux

# curl www.linuxidc.com:8001

this is linuxidc bbs

基于ip地址的虚拟主机配置:

通过ip来访问,需要配置多个ip;

# ifconfig eth0:1 192.168.22.21

server

{

listen 192.168.20.20:80;

server_name www.linuxidc.com;

root /data/www;

}

server

{

listen 192.168.20.21:80;

server_name www.linuxidc.com;

root /data/bbs;

}

验证结果,使用curl测试,或者浏览器输入域名访问;

# curl 192.168.22.20

this is linuxidc linux

# curl 192.168.22.21

this is linuxidc bbs

Windows 下nginx 配置tp虚拟机

server {
listen 80;
server_name local.test.com;
root "C:\Users\Administrator\Desktop\yes1";
location / {
index index.html index.htm index.php;
#autoindex on;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
} }
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}

注意:根目录名字不能出现test这个词

Nginx下配置虚拟主机的三种方法的更多相关文章

  1. nginx 配置虚拟主机的三种方法

    nginx,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的管 ...

  2. Apache配置虚拟主机的三种方法(基于IP、端口、域名)

    1 Apache虚拟主机的实现方式有3种. 基于IP的虚拟主机 基于端口的虚拟主机 基于域名的虚拟主机 2.1 启用虚拟主机的准备工作 2.1.1安装httpd [root@mail httpd]# ...

  3. nginx下配置虚拟主机

    linux 虚拟机下配置虚拟主机 nginx.conf 文件不动, 在 conf.d 或者 conf 目录下 新建项目.conf server { listen 80; server_name loc ...

  4. apache配置虚拟主机的三种方式

    Apache 配置虚拟主机三种方式   一.基于IP 1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP: [root@localhos ...

  5. Centos7 Apache配置虚拟主机的三种方式

    https://blog.csdn.net/tladagio/article/details/80760261 一.虚机主机的三种方式 1.基于IP 2.基于IP+端口 3.基于域名 官网文档:htt ...

  6. linux虚拟主机的三种方法

    虚拟主机虚拟主机是将一台(或者一组)服务器的资源(系统资源.网络带宽.存储空间等)按照一定的比例分割成若干相对独立的“小主机”的技术.每一台这样的“小主机”在功能上都可以实现WWW.FTP.Mail等 ...

  7. wampserver下配置虚拟主机 实现多站点支持

    wampserver下配置虚拟主机 实现多站点支持 wampserver是由德国人开发,在windows环境下实现apache+php+mysql的一款集成环境软件,wampserver自带SQLit ...

  8. Linux下查看磁盘挂载的三种方法

    Linux下查看磁盘挂载的三种方法 2009-06-05 23:17 好久没有更新日志了,呵呵.不是没有要写的东东.实在抽不出时间来写,要准备公司的考试呢,C++考试.已经有七个月没有写C++代码了, ...

  9. linux环境下配置虚拟主机域名

    linux环境下面配置虚拟主机域名 第一步:在root目录下面(即根目录)ls(查看文件)cd进入etc目录find hosts文件vi hosts 打开hosts文件并进行编辑在打开的文件最下面添加 ...

随机推荐

  1. BSScrollViewEdgePop

    https://blog.csdn.net/qq_17190231/article/details/84201956 2018年11月18日 16:52:39 FreeBaiShun 阅读数:66 标 ...

  2. yarn 在Vue框架中的常用命令

    初始化项目 yarn add init 安装vue yarn add vue 安装webpack,webpack-dev-server(是一个小型的Node.js Express服务器) yarn a ...

  3. 1.promethues监控融入k8s

    文档链接地址 https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_confi ...

  4. 苹果“抄袭”雷军PPT?小米高管如此评论

    3月26日凌晨,苹果如期举行了春季发布会,但发布会上并没有发布任何新硬件,主角全部是电视.游戏.信用卡等软件新品,值得一提的是,在苹果PPT上,有一张将硬件/软件/服务三部分单独提炼出来. “抄袭”雷 ...

  5. Python之Mock的入门

    参考文章: https://segmentfault.com/a/1190000002965620 一.Mock是什么 Mock这个词在英语中有模拟的这个意思,因此我们可以猜测出这个库的主要功能是模拟 ...

  6. JPA:identifier of an instance of was altered from

    由于前台提交的对象,并没有关联对象的数据. 所以要把关联对象赋值一下,在合并集合. WmsOutboundreport entity2 = service.findOne(item.getOutbou ...

  7. 网路知识总结(session&&Cookie&&三次握手&&请求头)

    1. 请说明Session和Cookie的作用和区别 1) Cookie 存在前端 前端需要拿着cookie访问后端,Session在服务器上(文件,数据库,如Redis) 2) web访问Serve ...

  8. app Inventor

    什么是App Inventor  ? MIT 官方网站 http://ai2.appinventor.mit.edu/Ya_tos_form.html 广州中文镜像网站 http://app.gzjk ...

  9. C++ 黑白棋AI minimax+alphabeta剪枝

    没事写着玩玩,通过debian上的黑白棋测试,搜了10层,打hard应该问题不大 #include <cstdio> #include <cstring> using name ...

  10. Asp.netMVC模型

    Model负责在View和控制器之间进行数据的传递:用户输入的内容封装为Model对象,发给Controller:要显示的数据有Controller放到Model中,然后扔给View去显示.Contr ...