欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Nginx配置文件说明

程序员文章站 2022-05-07 08:18:31
...

Nginx的配置文件:/usr/local/nginx/conf/nginx.conf

nginx.conf默认配置:

[[email protected] conf]# cat nginx.conf

# 全局块
#user  nobody;
worker_processes  1; #工作线程数,一般设置为CPU个数*单个CPU核数

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


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


# http块, 配置http服务器
http {
    include       mime.types; #引入的文件
    default_type  application/octet-stream;

    # 定义日志格式: main是格式名称,默认格式,也可以添加自定义格式
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    # main格式记录的内容是:
    # 远程IP - 远程用户[用户时间] 请求方法(如GET/POST)和协议
    # 状态  请求体body长度  referer来源信息
    # 用户代理  被转发的请求的原始IP 
    # 注: http_x_forwarded_for:在经过代理时,代理把你的本来IP加在此头信息中,传输你的原始IP

    #access_log  logs/access.log  main; #设置访问日志,第一个参数指定日志文件,第二个参数指定日志文件使用的格式

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65; #客户端与nginx的长连接时间,单位秒,设置为0则禁用
    server_tokens   off; #报错时不显示Nginx版本号

    #gzip  on;

    # server块
    server {
        listen       80; #监听端口
        server_name  localhost;  #监听域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main; 

        location / { #定位
            root   html;  #指定的路径,可以是绝对路径也可以是相对路径(相对nginx的安装路径/url/local/nginx)
            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  /50x.html;
        location = /50x.html {
            root   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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}