Nginx上配置虚拟机
来源:互联网 发布:女生一个人旅行 知乎 编辑:程序博客网 时间:2024/05/16 13:59
基于IP地址的虚拟主机配置,在一台主机上有多个IP的情况。
不同的IP对应不同的网站内容,客户端可以通过IP访问不同的网页内容。
为服务器添加多个IP地址:
ifconfig eth0:1 192.168.2.5 netmask 255.255.255.0 up
ifconfig eth0:2 192.168.2.6 netmask 255.255.255.0 up
在/etc/nginx/conf.d目录下新建一个iphost.conf,内容如下
server
{
listen 192.168.2.5:80;
server_name 192.168.2.5;
access_log /var/log/nginx/iphost1.access.log main;
error_log /var/log/nginx/iphost1.error.log warn;
location / {
root /var/www/nginx/site1;
index index.html index.htm;
}
}
server
{
listen 192.168.2.6:80;
server_name 192.168.2.6;
access_log /var/log/nginx/iphost2.access.log main;
error_log /var/log/nginx/iphost2.error.log warn;
location / {
root /var/www/nginx/site2;
index index.html index.htm;
}
}
在/etc/nginx/conf.d目录下新建一个vhost.conf,内容如下
基于主机头的虚拟主机配置,Web服务器上只有一个IP,
服务器根据客户端请求的host判断请求的是哪一个web站点。
server
{
listen 80;
server_name tec.test.com;
access_log /var/log/nginx/iphost1.access.log main;
error_log /var/log/nginx/iphost1.error.log warn;
location / {
root /var/www/nginx/site1;
index index.html index.htm;
}
}
server
{
listen 80;
server_name mkt.test.com;
access_log /var/log/nginx/iphost2.access.log main;
error_log /var/log/nginx/iphost2.error.log warn;
location / {
root /var/www/nginx/site2;
index index.html index.htm;
}
}
如果没有配置DNS,可以修改客服端host文件来测试。
通过tec.test.com访问的则为//var/www/nginx/site1的内容。
通过mkt.test.com访问的则为/var/www/nginx/site2的内容。
不同的IP对应不同的网站内容,客户端可以通过IP访问不同的网页内容。
为服务器添加多个IP地址:
ifconfig eth0:1 192.168.2.5 netmask 255.255.255.0 up
ifconfig eth0:2 192.168.2.6 netmask 255.255.255.0 up
在/etc/nginx/conf.d目录下新建一个iphost.conf,内容如下
server
{
listen 192.168.2.5:80;
server_name 192.168.2.5;
access_log /var/log/nginx/iphost1.access.log main;
error_log /var/log/nginx/iphost1.error.log warn;
location / {
root /var/www/nginx/site1;
index index.html index.htm;
}
}
server
{
listen 192.168.2.6:80;
server_name 192.168.2.6;
access_log /var/log/nginx/iphost2.access.log main;
error_log /var/log/nginx/iphost2.error.log warn;
location / {
root /var/www/nginx/site2;
index index.html index.htm;
}
}
在/etc/nginx/conf.d目录下新建一个vhost.conf,内容如下
基于主机头的虚拟主机配置,Web服务器上只有一个IP,
服务器根据客户端请求的host判断请求的是哪一个web站点。
server
{
listen 80;
server_name tec.test.com;
access_log /var/log/nginx/iphost1.access.log main;
error_log /var/log/nginx/iphost1.error.log warn;
location / {
root /var/www/nginx/site1;
index index.html index.htm;
}
}
server
{
listen 80;
server_name mkt.test.com;
access_log /var/log/nginx/iphost2.access.log main;
error_log /var/log/nginx/iphost2.error.log warn;
location / {
root /var/www/nginx/site2;
index index.html index.htm;
}
}
如果没有配置DNS,可以修改客服端host文件来测试。
通过tec.test.com访问的则为//var/www/nginx/site1的内容。
通过mkt.test.com访问的则为/var/www/nginx/site2的内容。
- Nginx上配置虚拟机
- 在虚拟机(CentOS)上配置fastdfs+nginx
- VMware虚拟机上配置nginx后,本机无法访问问题
- VMware虚拟机上配置nginx后,本机无法访问问题
- nginx之 nginx虚拟机配置
- Nginx 配置虚拟机
- Nginx 配置虚拟机
- nginx配置虚拟机
- nginx虚拟机配置
- 关于nginx的配置虚拟机
- Linux中nginx配置虚拟机
- nginx上配置php
- Nginx 上配置 HTTP2
- nginx配置虚拟机遇到的坑
- mac上php+nginx配置
- nginx上配置https服务器
- nginx虚拟机
- 虚拟机上redhat9 minicom的配置
- 物化视图
- syslogd 扫盲
- Ubuntu笔记:系统使用,程序调试报错等
- 变量冲突问题
- PHP中echo(),print(),print_r()的区别
- Nginx上配置虚拟机
- 回调函数实现例子-c语言
- PHP导出CSV后,不换行分析
- windows8 修改hosts文件
- CFStringRef和NSString相互转换
- 抖动动画效果
- Python:类与对象的变量[SimpleClass.py]
- Hive的图形化工具HWI
- 【ARM学习笔记】二、S3C2440A的GPIO(通用输入输出)引脚简介