nginx.conf文件介绍
使vim打开nginx配置文件有颜色
cp -a /home/iflytek/nginx-1.16.0/contrib/vim/* /usr/share/vim/vimfiles/
user nobody;
worker_processes 1;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format jfedu '$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;
tcp_nopush on;
keepalive_timeout 65;
keepalive_requests 100 :设置nginx在保持连接状态最多能处理的请求数,到达请求数,即使还在 保持连接状态时间内,也需要重新连接。
提示:可以用netstat -ntlpa |grep 80 查看链接状态
gzip on;
gzip_min_length 1k;
gzip_types text/plain text/xml;
gzip_comp_level 3;
server {
listen 8080;
server_name v1.jfedu.net;
charset utf-8;
access_log logs/host.access.log jfedu;
location / {
root /home/nginx/v1;
index index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
配置测试
编译安装nginx
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
cd /home/nginx-1.16.0 --进入解压后的目录
./configure --prefix=/home/hadoop/nginx --with-http_stub_status_module
或者
./configure --prefix=/home/hadoop/nginx
make && make install
cd /home/hadoop/nginx/sbin/
./nginx
nginx -v
文件配置
1.创建目录
mkdir -p /home/hadoop/nginx/{v1,v2,v3}

2. 将html文件夹中的文件分别复制到v1/v2/v3三个目录下
注:可以自行创建,并添加内容
cp html/* v1
cp html/* v2
cp html/* v3

3.修改index.html
将v1/v2/v3目录下的index.html文件进行修改,v1.jfedu.net为域名,用于后续进行区分,index.html可以进行自定义,能区分就行 
4.hosts中添加域名
linux中
vim /etc/hosts
#添加如下内容
192.168.31.8 v1.jfedu.net v2.jfedu.net v3.jfedu.net
 window 中 如果本地windows系统也需要访问,在C:\Windows\System32\drivers\etc目录下修改hosts文件,将上面域名添加到hosts文件中 
5. nginx.conf配置
按照章节前的文件介绍进行配置,此时我们多加两个server,具体内容如下:
server {
listen 8081;
server_name v2.jfedu.net;
charset utf-8;
access_log logs/v2.access.log jfedu;
location / {
root /home/nginx/v2;
index index.html index.htm;
}
}
server {
listen 8081;
server_name v3.jfedu.net;
charset utf-8;
access_log logs/v3.access.log jfedu;
location / {
root /home/nginx/v3;
index index.html index.htm;
}
6.重启服务
cd sbin
./nginx -s reload 如果重启报错,可根据报错信息查看配置文件
通过linux服务器进行访问  通过windows进行访问  
== 注意 ==
1.注意配置文件中符号不要有遗漏
2.端口不可以被其他服务占用
3.user nobody; 如果配置文件中配置的是普通用户,注意文件目录的权限,特别是创建的v1/v2/v3目录是否和启动nginx用户是同一个用户。否则访问会报错权限问题
|