一, 基于域名的虚拟机主机实战
1, 修改配置文件, 分别创建以域名 www.kang.com 与 bbs.kang.com 为监听对象网站
- 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.kang.com;
- location / {
- root html/www;
- index index.html index.htm;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- server {
- listen 80;
- server_name bbs.kang.com;
- location / {
- root html/bbs;
- index index.html index.htm;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
2, 测试域名访问是否正常
- [root@localhost nginx-1.6.3]# mkdir html/www
- [root@localhost nginx-1.6.3]# mkdir html/bbs
- [root@localhost nginx-1.6.3]# echo "www">> html/www/index.html
- www html/www/index.html
- [root@localhost nginx-1.6.3]# echo "bbs">> html/bbs/index.html
- bbs html/bbs/index.html
- [root@localhost nginx-1.6.3]# curl www.kang.com
- www
- [root@localhost nginx-1.6.3]# curl bbs.kang.com
- bbs kang.com
一, 基于端口的虚拟机主机实战
1,www 使用 80 端口 bbs 使用 81 端口, 配置文件如下
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80; #80 端口
- server_name www.kang.com;
- location / {
- root html/www;
- index index.html index.htm;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- server {
- listen 81; #81 端口
- server_name kang.kang.com;
- location / {
- root html/bbs;
- index index.html index.htm;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2687609.html