search

Home  >  Q&A  >  body text

nginx configuration problem: the specified directory restricts browser access

server {
    listen 80;
    server_name 域名已隐藏;
    index index.html index.htm index.php;
    root /home/wwwroot;
    
    # 这一段有什么问题吗 怎么不起作用
    location /app/ {
        if ($http_user_agent ~* "MicroMessenger") {
            set $notweixin 1;
        }
        if ($notweixin) {
            return 404;
        }
    }

    location ~ .*\.(php|php5)?$ {
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
    expires 30d;
    }
    location ~ .*\.(js|css)?$ {
    expires 7d;
    }
}
仅有的幸福仅有的幸福2755 days ago787

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-05-16 17:23:11

    Isn’t it possible to return 404 directly in if ($http_user_agent)?

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 17:23:11

    Regular matching has higher priority than path matching, that is to say, if your url path suffix is ​​php, it will not be matched

    reply
    0
  • ringa_lee

    ringa_lee2017-05-16 17:23:11

    location ^~ /app/

    What about this?

    reply
    0
  • Cancelreply