13,nginx的虚拟主机的配置
[root@moban conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.etiantian.org;
root html/www;
index index.html index.htm;
}
server {
listen 80;
server_name bbs.etiantian.org;
root html/bbs;
index index.html index.htm;
}
server {
listen 80;
server_name blog.etiantian.org;
root html/blog;
index index.html index.htm;
}
}
[root@moban conf]# for n in www blog bbs;do cat ../html/$n/index.html ;done
www.etiantian.org
blog.etiantian.org
bbs.etiantian.org
[root@moban conf]#
[root@moban conf]#
配置好站点后可以在Linux服务器配置hosts 文件,然后通过域名访问,看看服务正常不。
然后再在windows的hosts文件配置,这样就可以通过浏览器访问域名了
如果没有www/index.html 文件(首页文件),curl www.etiantian.org 会报403 错误。
rewrite 跳转,浏览器的网址会变化为www.jeffl...........

访问IP,就是到你的第一个虚拟主机,所以你可以在第一个虚拟主机做rewrire。防止别人
养自己的域名。所以第一个域名啥也不做,最好是只做跳转。
nginx 日志切割:(每天定时0点执行脚本)
[root@moban ~]# cat cut_nginx_log.sh
cd /application/nginx/logs &&\
mv www_access.log www_access_$(date +%F -d -1day).log
/application/nginx/sbin/nginx -s reload
[root@moban ~]#
一 基于端口的虚拟主机:
基于端口的话,你输入ip+端口和域名加端口的效果是一样的。
下面无论你配置多少个不同域名,只要他们的端口不一样,你都可以通过IP+端口访问,对应的网站。
二 基于IP的虚拟主机:(这个企业不用)
server {
listen 192.168.132.131:800;
server_name bbs.etiantian.org;
root html/bbs;
index index.html index.htm;
}
server {
listen 192.168.132.131:8000;
server_name blog.etiantian.org;
root html/blog;
index index.html index.htm;
}

浙公网安备 33010602011771号