• nginx的使用


    1,nginx的目录结构

     1 .
     2 ├── client_body_temp
     3 ├── conf                 #nginx所有配置文件的目录
     4 │   ├── fastcgi.conf
     5 │   ├── fastcgi.conf.default
     6 │   ├── fastcgi_params
     7 │   ├── fastcgi_params.default
     8 │   ├── koi-utf
     9 │   ├── koi-win
    10 │   ├── mime.types
    11 │   ├── mime.types.default
    12 │   ├── nginx.conf        #nginx的主配置文件
    13 │   ├── nginx.conf_bak
    14 │   ├── nginx.conf.default
    15 │   ├── scgi_params
    16 │   ├── scgi_params.default
    17 │   ├── uwsgi_params
    18 │   ├── uwsgi_params.default
    19 │   ├── vhosts
    20 │   │   ├── default.conf   #不该有,由于我配置了zabbix所以有
    21 │   │   └── zabbix.conf
    22 │   └── win-utf
    23 ├── fastcgi_temp    #临时数据目录
    24 ├── html
    25 │   ├── 1.php
    26 │   ├── 50x.html
    27 │   └── index.html
    28 ├── logs            #日志目录
    29 │   ├── access.log
    30 │   ├── error.log
    31 │   ├── nginx_error.log
    32 │   └── nginx.pid
    33 ├── proxy_temp      #临时目录
    34 ├── sbin            #nginx的命令的目录
    35 │   ├── nginx
    36 │   └── nginx.old
    37 ├── scgi_temp
    38 └── uwsgi_temp

    2配置文件讲解
    安装好之后在没有配置的情况下,nginx的配置文件说明

    简洁版:

     1 worker_processes  1;
     2 error_log  logs/error.log;
     3 pid        logs/nginx.pid;
     4 
     5 events {
     6     worker_connections  1024;
     7 }
     8 
     9 http {
    10     include       mime.types;
    11     default_type  application/octet-stream;
    12     sendfile        on
    13     keepalive_timeout  65;

          log_format main '$remote_addr $host $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
               '"$http_user_agent" "$http_accept_language" "$request_time" '
              '"$upstream_response_time" "$upstream_addr" "$upstream_status" "$http_x_real_ip" "$proxy_add_x_forwarded_for"';

      14 server {

    15         listen       80;
    16         server_name  localhost;
    17         location / {
    18             root   html;
    19             index  index.html index.htm;
    20         }
    21         location = /50x.html {
    22             root   html;
    23         }
    24     }
    25         
    26         
    27         server {
    28         listen       80;
    29         server_name  www.123.com;
    30         location / {
    31             root   html;
    32             index  index.html index.htm;
    33         }
    34         location = /50x.html {
    35             root   html;
    36         }
    37   }  
    38 }  
    39 main分区位于最上层--包含1-3行  核心功能模块
    40 main下面包含events分区 ----5-7行 核心功能模块
    41 main分区下面包含http分区在第九行
    42 每个http分区可以包含一个或者多个server分区(14-24行)
    43 每个server区中又可以有一个或者多个location区(17-20或者21-24)

    详细版

      1 #user  nobody;        #运行用户
      2 worker_processes  1;  #nginx进程数,建议设置为等于CPU总核心数。
      3 
      4 #error_log  logs/error.log;   #全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
      5 #error_log  logs/error.log  notice;
      6 #error_log  logs/error.log  info;
      7 
      8 #pid        logs/nginx.pid;   #进程文件
      9 
     10 
     11 events {
     12     worker_connections  1024;  #每个work进程支持的最大进程数
     13 }
     14 
     15 
     16 http {
     17     include       mime.types;    #文件扩展名与文件类型映射表
     18     default_type  application/octet-stream; #默认文件类型
     19 
     20     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
     21     #                  '$status $body_bytes_sent "$http_referer" '
     22     #                  '"$http_user_agent" "$http_x_forwarded_for"';
     23 
     24     #access_log  logs/access.log  main; #设定访问日志的日志记录格式
     25 
     26     sendfile        on;  #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on
     27     #tcp_nopush     on;  #激活tcp_nodelay,内核会等待将更多的字节组成一个数据包,从而提高I/O性能
     28 
     29     #keepalive_timeout  0;
     30     keepalive_timeout  65;  #连接超时时间,单位是秒
     31 
     32     #gzip  on;  #开启gzip压缩
     33 
     34     server {
     35         listen       80;   #侦听80端口
     36         server_name  localhost;  #提供服务的域名主机名
     37 
     38         #charset koi8-r;  #默认编码
     39 
     40         #access_log  logs/host.access.log  main;
     41 
     42         location / {      #第一个location区块开始
     43             root   html;  #站点根目录
     44             index  index.html index.htm;  默认首页文件
     45         }
     46 
     47         #error_page  404              /404.html;  #错误页面
     48 
     49         # redirect server error pages to the static page /50x.html
     50         #
     51         error_page   500 502 503 504  /50x.html;  #出现对应的状态码的时候,使用50x.html回应
     52         location = /50x.html {      #location区块开始,访问50x.html
     53             root   html;
     54         }                          #http区块结束
     55 
     56         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     57         #对 "/" 启用反向代理
     58         #location ~ .php$ {
     59         #    proxy_pass   http://127.0.0.1;
     60         #}
     61 
     62         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     63         #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
     64         #location ~ .php$ {
     65         #    root           html;
     66         #    fastcgi_pass   127.0.0.1:9000;
     67         #    fastcgi_index  index.php;
     68         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
     69         #    include        fastcgi_params;
     70         #}
     71 
     72         # deny access to .htaccess files, if Apache's document root
     73         # concurs with nginx's one
     74         #
     75         #location ~ /.ht {
     76         #    deny  all;
     77         #}
     78     }
     79 
     80 
     81     # another virtual host using mix of IP-, name-, and port-based configuration
     82     #第二个server模块,同上
     83     #server {
     84     #    listen       8000;
     85     #    listen       somename:8080;
     86     #    server_name  somename  alias  another.alias;
     87 
     88     #    location / {
     89     #        root   html;
     90     #        index  index.html index.htm;
     91     #    }
     92     #}
     93 
     94 
     95     # HTTPS server
     96     #配置web支持https服务
     97     #server {
     98     #    listen       443 ssl;
     99     #    server_name  localhost;
    100     #证书
    101     #    ssl_certificate      cert.pem;
    102     #    ssl_certificate_key  cert.key;
    103 
    104     #    ssl_session_cache    shared:SSL:1m;
    105     #    ssl_session_timeout  5m;
    106 
    107     #    ssl_ciphers  HIGH:!aNULL:!MD5;
    108     #    ssl_prefer_server_ciphers  on;
    109 
    110     #    location / {
    111     #        root   html;
    112     #        index  index.html index.htm;
    113     #    }
    114     #}
    115 
    116 }
    View Code
  • 相关阅读:
    ios 设置本地化显示的app名称
    iOS 统一配置
    iPhoneX && iOS11 适配
    手机如何和电脑 无线连接 使用adb命令配合连接
    使用adb命令查看APP包名 和 包入口方法
    Charles下载及安装破解-自己编辑
    修改表里面里面的 所有账号的密码
    Xshell6会话管理器无意中关闭,在哪里打开
    工作中常用的Linux命令
    使用adb命令连接模拟器且安装apk
  • 原文地址:https://www.cnblogs.com/Dicky-Zhang/p/5952334.html
Copyright © 2020-2023  润新知