5 Nginx配置介绍

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

 

页面访问

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值