虚拟主机配置
2017-07-20 本文已影响55人
ifcoder
什么是虚拟主机?
虚拟主机是一种特殊的软硬件技术,它可以将网络上的每一台计算机分成多个虚拟主机,每个虚拟主机可以独立对外提供www服务,这样就可以实现一台主机对外提供多个web服务,每个虚拟主机之间是独立的,互不影响的
通过nginx可以实现虚拟主机的配置,nginx支持三种类型的 虚拟主机配置,
- 基于ip的虚拟主机, (一块主机绑定多个ip地址) ----设置虚拟ip--listen 192.168.20.21:80 你懂的;
- 基于域名的虚拟主机(servername不同,listen监听的端口相同)
- 基于端口的虚拟主机(listen的端口不同,servername相同)
添加虚拟ip命令如下:
ifconfig eth0:1 192.168.35.123 netmask 255.255.255.0
nginx.conf下的配置
http{
server{
#表示一个虚拟主机
}
}
nginx.conf文件
#定义Nginx运行的用户和用户组
#user www www;
#nginx进程数,建议设置为等于CPU总核心数。
worker_processes 1;
#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
#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;
}
# load modules compiled as Dynamic Shared Object (DSO)
#
#dso {
# load ngx_http_fastcgi_module.so;
# load ngx_http_rewrite_module.so;
#}
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;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来 输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常 把这个改成off
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #长连接超时时间,单位是秒
#gzip on;
server {
listen 80; #监听端口
server_name www.liumanlin.com;#域名可以有多个,用空格隔开
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
location 映射
+ location [ = | ~ | ~* | ^~ ] uri { ... }
+ location URI {} //对当前路径及子路径下的所有对象都生效;
+ location = URI {} //注意URL最好为具体路径。精确匹配指定的路径,不包括子路径,因此,只对当前资源生效;
+ location ~ URI {} 或 location ~* URI {}
//模式匹配URI,此处的URI可使用正则表达式,~区分字符大小写,~*不区 分字符大小写;
+ location ^~ URI {} //不使用正则表达式
优先级: = > ^~ > ~|~* > /|/dir/
小记
完成本节自学的过程中,学习到了这些linux相关知识
-
域名解析文件为/etc/hosts
-
防火墙查看相关命令 -- service方式
service iptables status #查看防火墙状态
service iptables start #开启防火墙
service iptables start #关闭防火墙
-
防火墙查看相关命令 -- iptables方式
/etc/init.d/iptables status #查看防火墙状态
/etc/init.d/iptables stop #暂停防火墙
/etc/init.d/iptables restart #重启防火墙
-
chkconfig 功能说明:检查,设置系统的各种服务。
语法:
chkconfig [--add][--del][--list][系统服务]
或
chkconfig [--level <等级代号>][系统服务][on/off/reset]
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
语法:
chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name
on和off开关,系统默认只对运行级3,4,5有效,但是reset可以对所有运行级有效。
--level选项可以指定要查看的运行级而不一定是当前运行级。
--level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关毕。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动