linux高级---web虚拟主机的配置-server

linux高级—web虚拟主机的配置-server

一、修改nginx.conf

[root@localhost conf]# cat nginx.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]# 

二、新建首页文件及文件夹

# 在/usr/local/xwnginx/html下新建3个目录 feng   zhang  xiao,然后去新建首页index.html,里面的内容自己定义,例如welcome to **
[root@localhost html]# tree
.
├── 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 -t
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]# ulimit -n 1000000 #临时调整linux内核允许一个进程可以打开的文件数量,调整为100万
[root@localhost html]# ulimit -a
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 -t
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]# nginx -s reload
[root@localhost html]# ps aux | grep nginx
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]# 

四、域名解析

# 在windows里修改C:\Windows\System32\drivers\etc\hosts文件,进行域名解析
192.168.17.152  www.xiao.com
192.168.17.152  www.zhang.com
192.168.17.152  www.feng.com
# 修改小技巧:复制hosts文件到桌面,修改完成后,再复制过去覆盖

五、测试访问

# 再调出cmd命令行工具,测试域名是否生效

在这里插入图片描述

# 最后使用浏览器输入不同的域名测试访问

在这里插入图片描述

六、查看日志文件

[root@localhost html]# cd ../logs/
[root@localhost logs]# ls
access.log  error.log  feng.com.access.log  nginx.pid  xiao.com.access.log  zhang.com.access.log
[root@localhost logs]# ll
总用量 36
-rw-r--r--. 1 root root  7561 314 17:08 access.log
-rw-r--r--. 1 root root 10439 314 19:53 error.log
-rw-r--r--  1 root root   453 314 19:26 feng.com.access.log
-rw-r--r--  1 root root     4 314 17:16 nginx.pid
-rw-r--r--  1 root root  2126 314 19:53 xiao.com.access.log
-rw-r--r--  1 root root  1077 314 19:53 zhang.com.access.log
[root@localhost logs]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pod️

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值