Naginx 配置详解

#全局块(用户组、Pid存放地址、日志存放、配置文件引入、进程数)
#user  nobody;  #配置用户或者组,默认为nobody nobody。
worker_processes  1;    #允许生成的进程数,默认为1

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

#pid        logs/nginx.pid;     #指定nginx进程运行文件存放地址

#Events块(连接数、多网络连接、网络连接序列化)
events {
    worker_connections  1024;   #连接数
}

#Http块(server、配置代理、缓存、日志定义)
http {
    include       mime.types;   #文件扩展名与文件类型映射表(MIME映射表)
    default_type  application/octet-stream; #默认文件类型,默认为text/plain  
    #Content-Type: .*( 二进制流,不知道下载文件类型)---> application/octet-stream    例子说明 1.
    #Content-Type: .txt ---> text/plain 	例子说明 1.

    #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; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
    #tcp_nopush     on; #此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用

    #keepalive_timeout  0;  
    keepalive_timeout  65;  #连接超时时间,默认为75s,可以在http,server,location块。

    #gzip  on;  #gzip压缩

    server {
        listen       80;    #服务监听端口
        server_name  localhost;     #监听地址

        #charset koi8-r;    
        #charset utf-8,gbk;     #字符串设置为utf8

        #access_log  logs/host.access.log  main;    #访问日志

        location / {    #配置请求的路由,以及各种页面的处理情况
            root   html;    #根目录
            index  index.html index.htm;    #设置默认页
        }

        #error_page  404              /404.html;    #404页面

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;    #500/502/503/504页面
        location = /50x.html {  #属于50X页面则访问括号内页面
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {    #匹配到.php结尾的文件
        #    proxy_pass   http://127.0.0.1;     #请求转向127.0.0.1 定义的服务器列表
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;   #跳转到静态HTML页面
        #    fastcgi_pass   127.0.0.1:9000;     # 表示nginx通过fastcgi_pass将用户请求的资源
        #发给127.0.0.1:9000进行解析,这里的nginx和php脚本解析服务器是在同一台机器上,
        #所以127.0.0.1:9000表示的就是本地的php脚本解析服务器。
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name; #例子说明:3
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;     #禁止一个ip或者ip段访问
        #    allow   all;     #允许一个ip或者ip段访问
        #}
    }


    # 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;     #crt 文件的名称
    #    ssl_certificate_key  cert.key;     #key 文件的名称

    #    ssl_session_cache    shared:SSL:1m;    #ssl缓存大小,详细说明 4.  
    #    ssl_session_timeout  5m;   #客户端可以重用会话缓存中ssl参数的过期时间,
    #内网系统默认5分钟太短了,可以设成30m即30分钟甚至4h。

    #    ssl_ciphers  HIGH:!aNULL:!MD5;     #加密方式  详细说明 5.
    #    ssl_prefer_server_ciphers  on;     #设置协商加密算法时,优先使用我们服务端的加密套件,
    #而不是客户端浏览器的加密套件

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

}

例子说明:

  1. [root]
    语法:root path
    默认值:root html
    配置段:http、server、location、if

例如:
location ^~ /t/ {
root /www/root/html/;
}
如果一个请求的URI是/t/a.html时,web服务器将会返回服务器上的/www/root/html/t/a.html的文件。

  1. nginx的location配置详解
    https://www.cnblogs.com/sign-ptk/p/6723048.html

  2. fastcgi_param 参数说明
    https://www.cnblogs.com/codefly-sun/p/5934359.html

  3. nginx ssl配置
    https://blog.csdn.net/mr_raptor/article/details/51854746

  4. 加密方式说明
    https://segmentfault.com/a/1190000002866627

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值