为nginx主配置文件添加注释,更好的理解nginx

nginx的默认加载 /usr/share/nginx/html/ 文件

1.nginx主配置文件

打开 vim /etc/nginx/nginx.conf


user  nginx;  #设置nginx服务的系统使用用户
worker_processes  1;  #工作进程数 默认设置和cpu相同就好了

error_log  /var/log/nginx/error.log warn;   #错误日志
pid        /var/run/nginx.pid;   #进程的pid


events {
    worker_connections  1024;    #每个进程允许最大连接数
}


http {
    include       /etc/nginx/mime.types;  #设置http协议的Content-Type与扩展名对应关系
    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  /var/log/nginx/access.log  main;  # 设置日志类型与log_format 对应

    sendfile        on;  #零拷贝 nginx的一大优势,拷贝文件是不需要经过用户空间,直接在内核空间上拷贝
    #tcp_nopush     on; 

    keepalive_timeout  65;  #连接超时 65s

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;  #导入conf.d目录下的配置文件
}

小菜建议配服务的时候在/etc/nginx/conf.d/目录下新建一个文件后缀为.conf的文件

2.conf.d文件

在命令窗口输入

cd /etc/nginx/conf.d

进入到conf.d目录下面有个默认default.conf文件

server {
    listen       80;   #监听的端口号80 也可以这样写 192.168.1.140:80
    server_name  localhost;  #主机域名

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {    #访问的路径
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }   

    #error_page  404              /404.html;   #定义404的错误

    # redirect server error pages to the static page /50x.html
    #   
    error_page   500 502 503 504  /50x.html;  #定义 500 502 503 504错误
    location = /50x.html {
        root   /usr/share/nginx/html;
    }   

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #   
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}  

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #   
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

nginx教程

nginx环境搭建(1) nginx基础知识(2) nginx的安装 卸载(3) nginx的基本参数使用(4) nginx分析默认配置(5) nginx 虚拟主机配置(6) nginx 日志(7) nginx 模块(8) nginx 访问控制(9) nginx 静态资源web服务(10) nginx 缓存(11) nginx 跨域访问(12) nginx 防盗链(13) nginx 正向,反向代理配置(14) nginx 代理缓存配置(15) nginx websocket(16) nginx fastcgi(17) nginx 搭建wordPress博客(18) nginx Fastcgi缓存配置(19) nginx uwsgi反向代理(20) nginx 负载均衡(21) [深] nginx 动静分离(22) [深] nginx rewrite规则(23) [深] nginx 平滑升级 添加模块 调试(24) [深] nginx secure_link_module模块(25) [深] nginx geoip_module模块(26) [深] nginx https(27) [深] nginx与lua的开发(28) [架] nginx常见问题(29) [架] nginx性能优化(30) [架] nginx 安全(31) [架] nginx 反向代理gRpc(32)