《实战Nginx》读书笔记--Nginx配置文件

先看下一份的Nginx 的配置

复制代码
#user  nobody nobody;#使用的用户和组
worker_processes  4;#工作进程的个数,一般等于CPU核数或者总核数的两倍

#error_log  logs/error.log;#错误日志的存放路径 错误日志级别有[debug|info|notice|error|warn|crit]
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;#指定nginx pid 存放的路径


events {
 use epoll; #linux 推荐使用epoll freeBBD 推荐kqueue 模型
    worker_connections  1024;#单个进程最大连接数(最大连接数=连接数*进程数)
}


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;#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,
对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
#tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #长连接超时时间,单位是秒 gzip on;#启用Gizp压缩 gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml;#压缩的文件类型 #当前的Nginx的配置 server { listen 80;#监听80端口,可以改成其他端口 server_name 192.168.0.4;############## 当前服务的域名 #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } }
复制代码


Nginx 配置文件结构 是

……

events

{

  …………………

}

http

{

server{}

server{}

}

Nginx 虚拟主机的配置

基于ip地址的配置

复制代码
   server {
        listen       192.168.0.1:80;
        
        server_name  192.168.0.1

        location / {
            root   html1; #根目录
            index  index.html index.htm;#默认页
        }
    }
    #第二个虚拟主机
   server {
        listen       192.168.0.2:80;#监听的端口和ip
        #listen       somename:8080;
        server_name  192.168.0.2;#主机名

        location / {
            root   html2;
            index  index.html index.htm;
        }
    }
复制代码

基于域名的配置

复制代码
    server {
        listen       80;
        
        server_name  www.a.com;

        location / {
            root   html1; #根目录
            index  index.html index.htm;#默认页
        }
    }
    #第二个虚拟主机
   server {
        listen       80;
        server_name  www.b.com;

        location / {
            root   html2;
            index  index.html index.htm;
        }
    }
复制代码

基于端口的配置

复制代码
   server {
        listen       80;
        
        server_name  192.168.0.1;

        location / {
            root   html1; #根目录
            index  index.html index.htm;#默认页
        }
    }
    #第二个虚拟主机
   server {
        listen       81;
        server_name  192.168.0.1;

        location / {
            root   html2;
autoindex on;#列出文件目录
index index.html index.htm; } }
复制代码


 

 

posted @   闲云-野鹤  阅读(309)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示