Nginx虚拟主机配置
什么是虚拟主机
1 | 虚拟主机是一种特殊的软硬件技术,他可以将网络上每一台计算机分成多台虚拟主机, |

Nginx虚拟主机配置
Nginx配置解析的三种方式:
1 | 通过nginx可以实现虚拟主机的配置,nginx支持三种类型的虚拟主机配置 |
1 | 例如:基于虚拟机ip的配置,这里需要配置多个ip |
1.基于域名的虚拟主机
1.1.进入tengine目录
1 | [root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf |
1.2.更改nginx.conf文件
1 | [root@node1 conf]# vi nginx.conf |

1.3.配置第二个虚拟主机的访问页面
1 | [root@node1 conf]# cd /opt |
1.4.重新nginx服务
1 | [root@node1 html]# service nginx restart |

1.5.在window上进行ip地址映射【配置路由表】
1 | 【编辑C:\Windows\System32\drivers\etc\hosts文件】 |

1.6.查看配置是否成功
1 | 在地址栏输入:www.matrix.com |

1 | 在地址栏输入:www.matrix2.com |

2.基于ip的虚拟主机
2.1.进入tengine目录
1 | [root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf |
2.2.更改nginx.conf文件
1 | 一个主机对应多个ip地址 |

2.3.在Linux主机中设置虚拟ip
1 | [root@node1 html]# ifconfig eth0:1 192.168.230.18 netmask 255.255.255.0 |

2.4.重启nginx服务
1 | [root@node1 html]# service nginx restart |

2.5.在window上进行ip地址映射
1 | 【编辑C:\Windows\System32\drivers\etc\hosts文件】 |

2.6.查看配置是否成功
1 | 在地址栏输入:http://http://192.168.230.10/ |

1 | 在地址栏输入:http://http://192.168.230.18/ |

3.基于端口的虚拟主机
3.1.进入tengine目录
1 | [root@node1 ~]# cd /opt/modules/tengine-2.1.0/conf |
3.2.更改nginx.conf文件
1 | [root@node1 conf]# vi nginx.conf |

3.3.重启nginx服务
1 | [root@node1 html]# service nginx restart |

3.4.在window上进行ip地址映射
1 | 【编辑C:\Windows\System32\drivers\etc\hosts文件】 |

3.5.查看配置是否成功
1 | 在地址栏输入:http://http://192.168.230.10/ |

1 | 在地址栏输入:http://192.168.230.10:8088/ |

本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2016/02/22/Nginx虚拟主机配置/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
知识 & 情怀 | 二者兼得