笔记:nginx配置文件


#user  nobody;
worker_processes  1;                                    <- worker进程的数量,为了避免上下文切换,通常设置为cpu总核数-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;                           <- 每一个worker进程支持的最大连接数(相当于一个服务员能服务多少个客人)
}


http {                                                  <- HTTP区块开始
    include       mime.types;                           <- Nginx支持的媒体类型库文件
    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 {                                            <- 第一个Server区块开始,表示一个独立的虚拟机站点
        listen       80;                                <- 提供服务的端口,默认为80(响应请求的端口)
        server_name  localhost;                         <- 提供服务的域名主机名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {                                    <- 第一个location区块开始
            root   html;                                <- 站点的根目录,相当于Nginx的安装目录
            index  index.html index.htm;                <- 默认的首页文件,多个用空格分开
        }                                               <- 第一个location区块结束

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;        <- 出现对应的http状态码时,使用50x.html回应客户
        location = /50x.html {                          <- location区块开始,访问50x.html
            root   html;                                <- 指定对应的站点目录为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;
    #    }
    #}

}                                                       <- HTTP区块结束

server模块的作用(每一个server都必定有一个location):
1.类似于在门口等着接待客人的侍者,有多个server就是有多个侍者;配置服务监听信息
2.根据主机信息,确认是哪个侍者接待的客人,根据侍者安排客人的去向
3.最后交给location服务员进行处理

location模块的作用:
1.找UR信息
2.指明去哪找.
3.有指定要找的信息就是指定的信息相应,没有指定找的信息就默认找index.html响应

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;
}

注:当LNMP架构分台部署,“/scripts”需换成php的目录

猜你喜欢

转载自blog.csdn.net/weixin_44901564/article/details/107670304