美文网首页
Nginx主配置文件和默认配置配置(二)

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

作者: andpy | 来源:发表于2018-05-15 17:11 被阅读9次

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 

相关文章

  • Nginx默认配置语法

    nginx的配置文件 nginx 主要有两类默认配置文件 第一个是主配置文件 /etc/nginx/nginx.c...

  • nginx配置文件说明

    1 配置文件基础 默认的nginx服务器配置文件都存放在安装目录conf中,主配置文件名为nginx.conf,下...

  • nginx和mongdb的启动命令

    nginx nginx具体放置文件地址: nginx 默认配置文件地址: 虚拟目录配置文件 nginx启动和停止命...

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

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

  • nginx的location配置

    默认配置信息 可以发现配置文件由一下几个部分组成: nginx的默认主配置文件主要由main,events,htt...

  • nginx配置文件

    nginx配置文件nginx配置文件详解一、nginx配置文件 启动子进程程序默认用户 user nobody;...

  • Nginx(二)

    一、nginx目录结构和命令 二、配置文件的组成部分 三、主配置文件结构: 四部 四、nginx配置 五、http...

  • Nginx之负载均衡

    一 负载均衡准备 准备三台虚拟机或服务器 二 配置主服务器的Nginx配置文件 nginx 配置文件 三 配置负载...

  • 宝塔面板,Nginx的配置文件nginx.conf的路径位置

    nginx.conf文件路径: 多域名Nginx配置文件: 主配置文件nginx.conf,会将多域名的配置引入

  • [code.nginx] Nginx服务器基础配置

    默认的Nginx服务器配置文件都存放在安装目录conf中,主配置文件名为nginx.conf。文件中的注释标志为“...

网友评论

      本文标题:Nginx主配置文件和默认配置配置(二)

      本文链接:https://www.haomeiwen.com/subject/vqdydftx.html