当前位置:Gxlcms > PHP教程 > Nginx配置文件nginx.conf解读

Nginx配置文件nginx.conf解读

时间:2021-07-01 10:21:17 帮助过:28人阅读

这篇文章主要介绍了关于Nginx配置文件nginx.conf解读,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

打开一个全新配置的nginx的nginx.conf文件,文件结构大概是这个样子:

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {
    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;    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;    #gzip  on;

    server {
        listen       80;
        server_name  localhost;        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        # redirect server error pages to the static page /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;
        #}
    }    #
    #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;
    #    }
    #}}

一大堆代码看起来眼花缭乱,其实并不复杂,我们来看精简版的:

# 全局区worker_processes  1;  # 有1个工作的worker子进程#可以自行修改,但太大会造成相互争夺CPU,一般来说:子进程数 = CPU数 * 核数# 配置nginx的连接特性events {
    worker_connections  1024; # 1个worker子进程能同时允许的最大连接数}# http服务器主要段http {    # 设定mime类型,类型由mime.types文件定义
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; # 是否调用sendfile来
输出文件 keepalive_timeout 65; # 连接超时时间 # 虚拟主机段 server { listen 80; # 监听端口 server_name localhost; # 监听主机\域名\端口 # 定义访问响应 location / { root html; # 根目录定位 index index.html index.htm; # 默认访问页面定位 } # 定义错误提示页面 location = /50x.html { root html; } }

相关推荐:

Nginx配置文件nginx.conf详解

以上就是Nginx配置文件nginx.conf解读的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行