makeitall
V2EX  ›  Flask

nginx 处理 flask 静态文件的问题

  •  
  •   makeitall · Oct 27, 2016 · 6322 views
    This topic created in 3484 days ago, the information mentioned may be changed or developed.
    server {
        server_name  domain.com;
        rewrite ^(.*) http://www.domain.com$1 permanent;
    }
    server {
        listen 80;
    
        server_name  www.domain.com;
    
        location / {
            proxy_pass         http://127.0.0.1:8000/;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
        }
        location /static {
            root /var/www/domain/static/;
        }
    }
    
    

    这样子配置静态文件访问总是会出现 403 或 404 的错误,到底是哪里错了?谢谢。

    5 replies    2016-10-28 06:46:07 +08:00
    cluries
        1
    cluries  
       Oct 27, 2016   ❤️ 1
    location /static/ {
    alias /var/www/domain/static/;
    }
    lcorange
        2
    lcorange  
       Oct 27, 2016   ❤️ 2
    看 /var/log/nginx/error.log
    里面对你的静态文件报错是什么
    我觉得可能是你 root 后面路径里 /的问题,或者是文件权限的问题
    makeitall
        3
    makeitall  
    OP
       Oct 27, 2016
    @cluries 不是 alias 试过了。。。
    makeitall
        4
    makeitall  
    OP
       Oct 27, 2016
    @lcorange 谢谢,非常有用,发现原因了,是因为 root /var/www/domain/static/后面多了一个 static 。
    makeitall
        5
    makeitall  
    OP
       Oct 28, 2016
    @cluries 谢谢,我明白 alias 的意思了。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3368 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 11:21 · PVG 19:21 · LAX 04:21 · JFK 07:21
    ♥ Do have faith in what you're doing.