Nginx主配置文件和默认配置配置(二)

Nginx默认配置语法

//找到主配置文件
vim /etc/nginx/nginx.conf

//查看文件,默认的配置如下
#设置nginx服务的系统默认使用用户,一般不改
user  nginx;
#工作进程数,一般与cpu核心数一致  
worker_processes  1;
#nginx的错误日志
error_log  /var/log/nginx/error.log warn;
#nginx服务启动时候的pid
pid        /var/run/nginx.pid;


events {
    #每个进程允许最大连接数,最大可以到65535,一般的企业为10000,即可满足大部分企业要求.
    worker_connections  1024;
    #工作进程数,这个默认参数没有,可以不配置
    use
}

#http协议
http {
    #配置统一的请求头 content-type 参数
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
    #sendfile 这个nginx的优势
    sendfile        on;
    #tcp_nopush     on;
    
    #客户端和服务器超时的时间 秒
    keepalive_timeout  65;

    #gzip  on;
    #读到该配置文件时,也会去读以下目录的配置,会有默认的配置文件
    include /etc/nginx/conf.d/*.conf;
    
    #配置一个站点
    server {
        #监听端口
        listen 80;
        #ip,域名等信息
        server_name localhost;
        #默认访问的路径配置如:www.applelife.xyz/.. ;基于该路径下的路劲地址
        location / {
            root /usr/share/nginx/html;
            index index.html index.htm;
        }
        #统一的错误页面,遇到该请求码的时候,访问页面的路径,之后匹配下面的location
        error_page 500 502 503 504 /50x.html;
        #具体页面的路径
        location = /50x.html {
            #50x.html存放的路径
            root /usr/share/nginx/html;
        }
    }
    #配置多个
    server {
        ....
    }
}

etc/nginx/conf.d/*.conf;default.conf默认配置文件参数

server {
    #监听端口
    listen       80;
    #域名,地址
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    
    #一个server可以配置多个location,/ 表示默认访问的路径 首页路径
    location / {
        #存放页面的路径
        root   /usr/share/nginx/html;
        #首页文件 在上面目录下面的文件,以该文件作为首页加载
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #错误页面
    error_page   500 502 503 504 404  /50x.html;
    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服务
systemctl restart nginx.service 
//柔和的重启
systemctl reload nginx.service 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,092评论 19 139
  • Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音。了解发音是有意...
    萤火虫de梦阅读 100,133评论 9 468
  • Page 1:nginx 服务器安装及配置文件详解 CentOS 6.2 x86_64 安装 nginx 1.1 ...
    xiaojianxu阅读 12,724评论 1 41
  • feisky云计算、虚拟化与Linux技术笔记posts - 1014, comments - 298, trac...
    不排版阅读 9,404评论 0 5
  • 总有想写一些东西的冲动 反反复复欲言又止 没有去争取任何观众 也没有必要向观众诉说太多心声 文字是最直击人心的 在...
    哈特么阅读 1,594评论 0 0

友情链接更多精彩内容