2014-07-14 2 views
4

전 mod_wsgi에 익숙하지 않고 아파치를 통해 파일을 제공합니다. 나는 플라스크에 정말로 편안하지만 이것은 내 머리를 얻을 수없는 무언가이다. 나는 안녕하세요 - 세계 프로그램을하고 성공적으로 안녕하세요 세상을 표시! 이제 이미지 파일을 표시하려고했습니다. 그래서 난 내 hello-world.py 업데이트의 경우 :/var/www /에서 안녕하세요 세계아파치를 통해 정적 파일 제공

/hello-world 
    test.py 
    yourflaskapp.wsgi 
    /static 
     -203.jpg 
    /templates 
     -hello.html 

내 템플릿은 간단하다 :

from flask import * 
yourflaskapp = Flask(__name__) 

@yourflaskapp.route("/") 
def hello(): 
    file="203.jpg" 
    return render_template("hello.html",file=file) 
# return"HEY" 
if __name__ == "__main__": 
    yourflaskapp.run() 

내 디렉토리 구조는 무엇인가 등이

<!DOCTYPE html> 
<html><head><title>hi</title></head> 
<body> 
<img src="{{url_for('static',filename=file)}}"/> 
</body></html> 

내 아파치의 conf 파일은 다음과 같습니다

<VirtualHost *:80> 
    WSGIDaemonProcess yourflaskapp 
    WSGIScriptAlias//var/www/hello-world/yourflaskapp.wsgi 
    Alias /static/ /var/www/hello-world/static 
    Alias /templates/ /var/www/hello-world/templates 
    <Directory /var/www/hello-world> 
      WSGIProcessGroup yourflaskapp 
     WSGIApplicationGroup %{GLOBAL} 
     Order deny,allow 
     Allow from all 
    </Directory> 
     <Directory /var/www/hello-world/static> 
      Order allow,deny 
      Allow from all 
     </Directory> 
     <Directory /var/www/hello-world/templates> 
      Order allow,deny 
      Allow from all 
     </Directory> 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    LogLevel warn 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

브라우저를 열고 내 IP로 향하면 이미지 파일이 표시되지 않습니다. 내가 뭘 잘못 했니? 내가 따라야 할 다른 방법이 있습니까? 누군가가 플라스크 + mod_wsgi + apache2로 작업하는 것을 이해할 수있는 좋은 링크를 추천 할 수 있다면

+0

당신이 /가 직접 203.jpg'/{당신의-IP}'정적 쳤을 때 어떻게됩니까? –

답변

0

하위 URL에 정적 파일을 마운트 할 때 일반적으로 항상 슬래시의 균형을 유지하는 것이 좋습니다. 그래서 대신 :

Alias /static/ /var/www/hello-world/static 

사용 :

Alias /static /var/www/hello-world/static 
+0

무슨 차이가 있습니까? –

+0

아파치는 LHS에서 일치하는 것을 경로에서 제거하고 결과가 RHS에 추가되기 때문에. 따라서 '/ static/foo'를 사용하면 '/ var/www/hello-world/staticfoo'를 열려고 시도하는 'foo'를 제거하면 RHS에 추가 할 때/슬래시를 버렸을 때 올바른지 확인하십시오. 정확한 시나리오가 발생했는지 또는 특정 Apache 버전과 관련이 있는지를 기억할 수 없으므로 문제를 피하기 위해 일치한다고 제안하는 것입니다. –

+0

좋습니다, 감사합니다! 나는 그것을 바꿀 것이다. –

관련 문제