nginx 使用入门指南

1.常用执行指令

1)根据配置文件启动nginx   
nginx -c 配置文件所在绝对地址 
如:nginx -c /usr/local/nginx/conf/nginx.conf
2)修改配置文件后生效,前提nginx已启动
nginx -s reload

2.常用配置文件参数含义

#user java java; 指定该配置文件启动后的用户权限 默认为nobody
worker_processes  2; 指定程序启动后开启的进程数。
#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; 略
#worker_rlimit_nofile 65535; 略
#error_log  /var/log/nginx.log; 指定错误日志文件存放地址
#error_log  /usr/local/nginx/logs/error.log info;
error_log  /usr/local/nginx/logs/error.log;

events { 略
    use epoll;
    multi_accept on;
    accept_mutex off;
    worker_connections  65535;
}
http{ 略
    include   mime.types;
    server_tokens off;
    default_type  application/octet-stream;
    underscores_in_headers on;
    server_names_hash_bucket_size 128;
    gzip  on;
    gzip_min_length  1k;
    gzip_buffers   4  16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types       text/plain  application/x-javascript text/css application/xml application/x-httpd-php application/xhtml+xml;
    gzip_vary on;

    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;

    access_log /usr/local/nginx/logs/access.log; 指定链接日志文件存放地址
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'; 指定日志输出格式
    client_body_buffer_size 128k;
    proxy_connect_timeout  600;
    proxy_read_timeout   600;
    proxy_send_timeout 600;
    proxy_buffer_size 16k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 54k;
    proxy_temp_file_write_size 64k;
    proxy_ignore_client_abort on;

server { 具体代理配置
    listen 3333; 代理监听端口
#    server_name yixaing.juxinli.com 匹配head头中host,正常匹配顺序:全,前,后,正则,默认匹配略。

    charset utf-8; 指定字符编码
    autoindex on; 
    autoindex_exact_size on;
    autoindex_localtime on; 

        location /apiui { 匹配地址
           alias   /home/java/yx_h5; 指定资源位置 且直接替换匹配地址
       index index.html; 指定资源首页
           try_files $uri $uri/ /index.html; 在找不到资源时 尝试匹配设置匹配选项               
        }  
        location / { 匹配地址
           root   /home/java/yx_h5; 指定资源位置 替换匹配地址且在后加匹配地址值
           index index.html;
        }
}

}

3.自己推测的结论

在中代理资源匹配是,若存在多个location,且其中一个location中存在try_files,
那么优先执行所有location匹配,若找不到,再执行匹配的location中的try_files.

猜你喜欢

转载自blog.csdn.net/u013062667/article/details/79957904