cdsn123jian 2015-10-02 06:57 采纳率: 0%
浏览 1502

在下良辰,请教个问题,日后必有重谢!关于nginx和filter

新人,我写了个filter,浏览器访问localhost:8080/项目名/index.html可以拦截,但我用了nginx后访问就变成localhost/项目名/index.html
,静态资源就拦截不了了,action还是可以拦截的,怎么回事?我想在使用了nginx的项目拦截未登陆用户访问的静态资源比如*.html。求各位博友指教!图片说明

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-04 10:02
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # nginx.conf
    
    server {
        listen 80;
        server_name localhost;
    
        # 允许客户端直接访问localhost:8080/项目名
        location /projectname/ {
            return 302 https://$host$request_uri;
        }
    
        # 静态资源路径配置
        root /usr/share/nginx/html;
    
        # 配置过滤器
        location ~ \.html$ {
            include snippets/fastcgi_params;
            fastcgi_pass unix:/var/run/nginx.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $request_path_info;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param REQUEST_METHOD $http_method;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param HTTP_HOST $http_host;
            fastcgi_param REMOTE_ADDR $remote_addr;
            fastcgi_param REMOTE_USER $remote_user;
            fastcgi_param HTTPS $scheme;
            fastcgi_param CGI_SCRIPT_NAME /projectname/cgi-bin/;
            fastcgi_param CGI_ENVIRONMENT $env;
            fastcgi_param CGI_QUERY_STRING $QUERY_STRING;
            fastcgi_param CGI_REQUEST_URI $REQUEST_URI;
            fastcgi_param CGI_FILE_FORMAT $FILES[0]->type;
        }
    }
    

    以上就是nginx如何实现动态资源请求的处理。希望对您有所帮助!

    评论

报告相同问题?