Nginx实现虚拟机
来源:互联网 发布:天音淘宝复制大师3.02 编辑:程序博客网 时间:2024/06/11 13:11
区分不同的网站有三种方式:
1、ip区分
方法一:
使用标准的网络配置工具(比如ifconfig和route命令)添加lP别名:
当前ip配置情况:
在eth0网卡再绑定一个ip:192.168.101.103
/sbin/ifconfig eth0:1 192.168.101.103 broadcast 192.168.101.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.101.103 dev eth0:1
方法二:
1、将/etc/sysconfig/network-scripts/ifcfg-eth0文件复制一份,命名为ifcfg-eth0:1
修改其中内容:
DEVICE=eth0:1
IPADDR=192.168.25.103
其他项不用修改
2、重启系统
Nginx的配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server { #一个Server就是一个虚拟主机
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
}
基于ip的虚拟主机配置
server {
listen 80;
server_name 192.168.25.141;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-141;
index index.html index.htm;
}
}
server {
listen 80;
server_name 192.168.25.100;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-100;
index index.html index.htm;
}
}
Nginx重新加载配置文件。
2、端口区分
server {
listen 81;
server_name 192.168.25.141;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-81;
index index.html index.htm;
}
}
server {
listen 82;
server_name 192.168.25.141;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-82;
index index.html index.htm;
}
}
3、域名区分
最有用的虚拟主机配置方式。
一个域名只能绑定一个ip地址,一个ip地址可以被多个域名绑定。
可以修改host文件实现域名访问。
可通过软件修改,无需权限,访问目录等(此软件)
软件下载地址:
http://download.csdn.net/detail/qq1137623160/9823260
也可访问目录(C:\Windows\System32\drivers\etc)修改window的hosts文件。
基于域名的虚拟主机配置
server {
listen 80;
server_name www.itheima.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-www;
index index.html index.htm;
}
}
server {
listen 80;
server_name hehe.itheima.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-hehe;
index index.html index.htm;
}
}
修改配置文件后,需要nginx重新加载配置文件。
- Nginx实现虚拟机
- Nginx 实现虚拟机
- nginx虚拟机
- 【Nginx】nginx虚拟机设置
- CentOS环境下Nginx实现3台虚拟机负载均衡
- Nginx实现虚拟机(1.基于ip地址的虚拟主机)
- Nginx实现虚拟机(2.基于域名的虚拟主机)
- nginx之 nginx虚拟机配置
- Nginx上配置虚拟机
- Nginx 配置虚拟机
- Nginx 配置虚拟机
- nginx虚拟机搭建
- nginx配置虚拟机
- nginx虚拟机配置
- 关于nginx的配置虚拟机
- Linux中nginx配置虚拟机
- 虚拟机中Centos7 部署nginx
- ubuntu虚拟机中安装nginx
- JAVA开发面试题(二)
- js产生页面内的顺序序列号
- JS 解决跨域汇总
- Nginx的应用场景
- 如何观察一棵树
- Nginx实现虚拟机
- [leetCode刷题笔记]341. Flatten Nested List Iterator
- 欢迎使用CSDN-markdown编辑器
- react native实战
- react native集成到原有的项目中(iOS)
- React native全局变量的使用(跨组件的通信)
- 道2——未知攻,焉知防
- 学习总结 ~ (三)React Native 初学 之 sectionList
- 从云端到尘埃:工信部推出云计算规划