1 worker_processes 1;
开启的进程数量,默认的规则,几个cpu就开几个进程,默认安装开启一个进程
通过命令查询cpu信息
cat /proc/cpuinfo
cat /proc/cpuinfo| grep "processor"| wc -l
通过命令
ps aux |grep nginx 查看只有一个工作worker进程
尝试修改进程数为2 重新加载配置文件,查看有2个worker进程,且应用人为nginx编译配置的
2 日志记录
因为编译时候,已经记录日志记录地方,所有这段注释可以不打开
3最大链接数
并发数目。可以根据机器的负载能力来调整
events {
worker_connections 1024;
}
4 是否启用压缩功能
并发量大时候,可以提现出来
#gzip on;
5 虚拟主机
server {
listen 80; 端口
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main; 给每个虚拟主机,定义单独的日志
location / {
root html; 指定默认的根目录在哪里。没有指定默认的是usr/html
index index.html index.htm;
}
#error_page 404 /404.html; 错误界面 /根是上面定义的root根目录
error_page 500 502 503 504 /50x.html; 错误界面
#location ~ \.php$ { //以php结尾的丢给一个服务器
# proxy_pass http://127.0.0.1;
#}
设置server配置本地hosts文件,访问 server8.example.com
server {
listen 80;
server_name server8.example.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
实例2
创建两个根目录
mkdir /var/www/web1 -pv
mkdir /var/www/web2 -pv
配置nginx
server {
listen 80;
server_name server8.example.com;
root /var/www/web1;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;buyaozhegele
index 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 default_server;
server_name www8.example.com
root /var/www/web2;
index index.html;
}
检查conf语法是否有编辑错误的
nginx -t -c /etc/nginx/nginx/nginx.conf.default
页面访问