linux高级—web虚拟主机的配置-server
一、修改nginx.conf
[root@localhost conf]
user xiaowei;
worker_processes 2;
error_log logs/error.log notice;
pid logs/nginx.pid;
events {
worker_connections 2048;
}
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;
keepalive_timeout 65;
server {
listen 80;
server_name www.feng.com;
access_log logs/feng.com.access.log main;
location / {
root html/feng;
index shouye.html index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.xiao.com;
access_log logs/xiao.com.access.log main;
location / {
root html/xiao;
index shouye.html index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.zhang.com;
access_log logs/zhang.com.access.log main;
location / {
root html/zhang;
index shouye.html index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
[root@localhost conf]
二、新建首页文件及文件夹
[root@localhost html]
.
├── 50x.html
├── feng
│ └── index.html
├── index.html
├── shouye.html
├── xiao
│ └── index.html
└── zhang
└── index.html
3 directories, 6 files
[root@localhost html]
三、重新加载nginx的配置
[root@localhost conf]
nginx: the configuration file /usr/local/xwnginx/conf/nginx.conf syntax is ok
nginx: [warn] 2048 worker_connections exceed open file resource limit: 1024
nginx: configuration file /usr/local/xwnginx/conf/nginx.conf test is successful
[root@localhost conf]
[root@localhost html]
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 3795
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1000000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 3795
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@localhost conf]
nginx: the configuration file /usr/local/xwnginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/xwnginx/conf/nginx.conf test is successful
[root@localhost conf]
[root@localhost html]
root 940 0.0 0.2 47016 2156 ? Ss 17:16 0:00 nginx: master process /usr/local/xwnginx/sbin/nginx
xiaowei 1373 0.0 0.2 47352 2912 ? S 19:31 0:00 nginx: worker process
xiaowei 1374 0.0 0.2 47352 2672 ? S 19:31 0:00 nginx: worker process
root 1388 0.0 0.0 112828 980 pts/0 S+ 19:50 0:00 grep --color=auto nginx
[root@localhost html]
四、域名解析
192.168.17.152 www.xiao.com
192.168.17.152 www.zhang.com
192.168.17.152 www.feng.com
五、测试访问
六、查看日志文件
[root@localhost html]
[root@localhost logs]
access.log error.log feng.com.access.log nginx.pid xiao.com.access.log zhang.com.access.log
[root@localhost logs]
总用量 36
-rw-r--r--. 1 root root 7561 3月 14 17:08 access.log
-rw-r--r--. 1 root root 10439 3月 14 19:53 error.log
-rw-r--r-- 1 root root 453 3月 14 19:26 feng.com.access.log
-rw-r--r-- 1 root root 4 3月 14 17:16 nginx.pid
-rw-r--r-- 1 root root 2126 3月 14 19:53 xiao.com.access.log
-rw-r--r-- 1 root root 1077 3月 14 19:53 zhang.com.access.log
[root@localhost logs]