• react-router 简单的nginx配置


     配置实例:

    http {
    
            ##
            # Basic Settings
            ##
    
            sendfile on;
            tcp_nopush on;
            tcp_nodelay on;
            keepalive_timeout 65;
            types_hash_max_size 2048;
            # server_tokens off;
    
            # server_names_hash_bucket_size 64;
            # server_name_in_redirect off;
    
            include /etc/nginx/mime.types;
            default_type application/octet-stream;
    
            ##
            # SSL Settings
            ##
    
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
            ssl_prefer_server_ciphers on;
    
            ##
            # Logging Settings
            ##
    
            access_log /var/log/nginx/access.log;
            error_log /var/log/nginx/error.log;
    
            ##
            # Gzip Settings
            ##
    
            gzip on;
            gzip_disable "msie6";
    
            # gzip_vary on;
            # gzip_proxied any;
            # gzip_comp_level 6;
            # gzip_buffers 16 8k;
            # gzip_http_version 1.1;
            # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    
            ##
            # Virtual Host Configs
            ##
            server {
                    listen 8080;  # 端口
                    server_name localhost;   # 绑定域名 
                    location ~ .*?.(js|css|jpg|png|jpeg|less|sass)   # 规则
                    {
                            root /home/uftp/react;  # web目录
                            expires 3d;  # 文件缓存时间
                            rewrite .*?([^/\]*?.(js|css|jpg|png|jpeg|less|sass)) /dist/$1 break; # rewrite:指令; .*?([^/\])*?.(js|css|jpg|png|jpeg|less|sass):匹配文件的正则; /dist/$1:($1正则匹配分组1内容,即文件名)重定向的文件路径
                    }
                    location / {
                            root /home/uftp/react;
                            try_files $uri /index.html;  # try_files:检查文件; $uri:监测的文件路径; /index.html:文件不存在重定向的新路径 
                            index index.html index.htm index.php; 
                    }
            }
            include /etc/nginx/conf.d/*.conf;
            include /etc/nginx/sites-enabled/*;
    }

    location规则

    ~      #波浪线表示执行一个正则匹配,区分大小写
    ~*    #表示执行一个正则匹配,不区分大小写
    ^~    #^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录
    =      #进行普通字符精确匹配
    @     #"@" 定义一个命名的 location,使用在内部定向时,例如 error_page, try_files

    首先匹配 =,其次匹配^~, 其次是按文件中顺序的正则匹配,最后是交给 / 通用匹配。当有匹配成功时候,停止匹配,按当前匹配规则处理请求。

    rewrite指令

    语法:rewrite regex replacement [flag];
    默认值:无
    作用域:server,location,if
    如果一个URI匹配指定的正则表达式regex,URI就按照replacement重写。
    rewrite按配置文件中出现的顺序执行。flags标志可以停止继续处理。
    如果replacement以"http://"或"https://"开始,将不再继续处理,这个重定向将返回给客户端。
    flag可以是如下参数
    last 停止处理后续rewrite指令集,然后对当前重写的新URI在rewrite指令集上重新查找。
    break 停止处理后续rewrite指令集,并不在重新查找,但是当前location内剩余非rewrite语句和location外的的非rewrite语句可以执行。
    redirect 如果replacement不是以http:// 或https://开始,返回302临时重定向
    permant 返回301永久重定向

  • 相关阅读:
    BZOJ3752 : Hack
    XIV Open Cup named after E.V. Pankratiev. GP of SPb
    XIII Open Cup named after E.V. Pankratiev. GP of Ukraine
    BZOJ2087 : [Poi2010]Sheep
    BZOJ2080 : [Poi2010]Railway
    BZOJ2082 : [Poi2010]Divine divisor
    Moscow Pre-Finals Workshop 2016. National Taiwan U Selection
    XIII Open Cup named after E.V. Pankratiev. GP of Asia and South Caucasus
    XIII Open Cup named after E.V. Pankratiev. GP of Azov Sea
    XIII Open Cup named after E.V. Pankratiev. GP of SPb
  • 原文地址:https://www.cnblogs.com/dudeyouth/p/6723962.html
Copyright © 2020-2023  润新知