一个web服务器搭建多个网站有三种方法
1 基于不同域名的虚拟网站
2 基于不同监听端口的虚拟网站
3 基于不同IP的虚拟网站
1 nginx 主配置文件解释
egrep -v “#|^$” nginx.conf.default > nginx.conf
vim /usr/local/nginx/conf/nginx.conf
worker_processes 1; #工作进程数 1个 跟服务器的核数保持一致 ngnix主进程:socket监听80端口 nginx线程接待用户,速度快
events {
worker_connections 1024; #进程里的线程数是1024个 最多65536个线程
}
http { #所有http里的是web函数
include mime. types;#导入文件 当前配置文件/usr/local/nginx/conf/ mime. types导入主配置文件nginx.conf
default_type application/octet-stream;
sendfile on; #发送文件 文件的高效传输 可以加参数开启压缩功能,把用户要看的信息压缩一下 增快传输速度
keepalive_timeout 65; #保持客户与服务器链接65秒不中断,不需要三次握手
server { #一个server代表一个网站
listen 80; #监听80 端口 可更改,写多少监听多少端口
server_name localhost; #网站域名 是统一资源标志符URI,相对网页目录的路径
location / { #location这个函数代表网页
root html; #网页目录路径 root是网页的根目录,是nginx的相对路径 可以绝对路径
index index.html index.htm; #一旦用户的uri只有一个根符号,就会跳转到 index.html或者 index.htm
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
2 制作网站
1 vim /usr/local/nginx/conf/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.yun.com;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
default_server 让用IP地址访问的用户强制进入本server函数
include导入 以配置文件的形式导入
nginx/conf 创建目录 mkdir extra
vim /usr/local/nginx/conf/nginx.conf #将server函数粘贴过来
server {
listen 80;
server_name bbs.yunjisuan.com;
#access_log logs/host.access.log main;
location / {
root html/bbs;
index index.html index.htm;
}
2 cd /usr/local/nginx/html
将里面的首页删除 rm -rf *
3 重建一个首页 :echo “hostname -I
” > index.html
4 /usr/local/nginx/sbin/nginx 启动nginx
#查看进程
[root@localhost html]# ps -ef | grep nginx
root 3028 1 0 04:28 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx #主进程 不负责接待
www 3029 3028 0 04:28 ? 00:00:00 nginx: worker process #线程 父进程为3082
哪个线程接待的用户,用户的最高权限就只是前面的 比如www,防止用户权限过高,所以接待用户的是程序权限,用户最高也是程序权限
5 curl 192.168.200.162 查看是否能够链接网页
6 将ip映射到域名