• Nginx配置文件


    1.Nginx目录

    /nginx
        ├── client_body_temp
        ├── conf                             # Nginx所有配置文件的目录
        │   ├── fastcgi.conf                 # fastcgi相关参数的配置文件
        │   ├── fastcgi.conf.default         # fastcgi.conf的原始备份文件
        │   ├── fastcgi_params               # fastcgi的参数文件
        │   ├── fastcgi_params.default       
        │   ├── koi-utf
        │   ├── koi-win
        │   ├── mime.types                   # 媒体类型
        │   ├── mime.types.default
        │   ├── nginx.conf                   # Nginx主配置文件
        │   ├── nginx.conf.default
        │   ├── scgi_params                  # scgi相关参数文件
        │   ├── scgi_params.default  
        │   ├── uwsgi_params                 # uwsgi相关参数文件
        │   ├── uwsgi_params.default
        │   └── win-utf
        ├── fastcgi_temp                     # fastcgi临时数据目录
        ├── html                             # Nginx默认站点目录
        │   ├── 50x.html                     # 错误页面优雅替代显示文件,例如当出现502错误时会调用此页面
        │   └── index.html                   # 默认的首页文件
        ├── logs                             # Nginx日志目录
        │   ├── access.log                   # 访问日志文件
        │   ├── error.log                    # 错误日志文件
        │   └── nginx.pid                    # pid文件,Nginx进程启动后,会把所有进程的ID号写到此文件
        ├── proxy_temp                       # 临时目录
        ├── sbin                             # Nginx命令目录
        │   └── nginx                        # Nginx的启动命令
        ├── scgi_temp                        # 临时目录
        └── uwsgi_temp                       # 临时目录
    View Code

    2.Nginx相关命令

    #查看 nginx 版本号
    nginx -v
    #启动 nginx
    start nginx
    #停止 nginx
    nginx -s stop
    #重新加载 nginx
    nginx -s reload
    View Code

    3.Nginx主配置文件(nginx.conf)

    #nginx用户、用户组
    user  nobody;
    #指定工作进程的个数,默认是1个。具体可以根据服务器cpu数量进行设置,比如cpu有4个,可以设置为4。
    #如果不知道cpu的数量,可以设置为auto。nginx会自动判断服务器的cpu个数,并设置相应的进程数。
    worker_processes  1;
    
    #错误日志文件的输出位置和输出级别[ debug | info | notice | warn | error | crit ]
    error_log  logs/error.log;
    error_log  logs/error.log  notice;
    error_log  logs/error.log  info;
    
    #指定nginx进程pid的文件路径
    pid        logs/nginx.pid;
    
    #一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除
    #但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
    worker_rlimit_nofile 1024;
    
    #这个指令块用来设置工作进程的工作模式以及每个进程的连接上限。
    events {
        #用来指定nginx的工作模式,通常选择epoll,除了epoll,还有select,poll。
        use epoll;
        #定义每个工作进程的最大连接数,默认是1024(最大连接数=连接数*进程数)。
        worker_connections  1024;
    }
    
    
    #http指令快
    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;
    
        #单位是秒,客户端连接时时间,超时之后服务器端自动关闭该连接 如果nginx守护进程在这个等待的时间里,
        #一直没有收到浏览发过来http请求,则关闭这个http连接
        keepalive_timeout  65;
    
        #开启gzip压缩输出
        gzip  on;
    
        #虚拟主机的配置
        server {
            #监听端口
            listen       8001;
            #域名
            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
            #
            # 定义错误提示页面
            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;
            #}
    
            #PHP 脚本请求全部转发到FastCGI处理. 使用FastCGI默认配置.
            #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;
            #}
            
            #禁止访问 .htxxx 文件
            #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;
        #    }
        #}
    
    }
    View Code
  • 相关阅读:
    Algorithms
    STL学习笔记 set
    HttpContext.Current
    Luence初始与简单应用Document的增删改查.
    [深入浅出Cocoa]iOS程序性能优化
    spring.net结合普通三层(实现IOC 及AOP中的异常记录功能)
    VS版权信息插件——初试VS插件开发小记
    快速开发平台 Putdb WebBuilder 6.9
    ObjectiveC学习及iOS开发的准备
    Visual Studio 2012 Update 2 自制iso下载
  • 原文地址:https://www.cnblogs.com/bl123/p/15739744.html
Copyright © 2020-2023  润新知