Flask Nginx url_for _external

时间:2016-09-01 03:17:55

标签: python nginx flask url-for

在Nginx下使用url_for _external = True(所以:url_for('foobar', _external=True))时,如何使服务器名称替换localhost?

我正在运行烧瓶应用程序。

nginx设置

server {
    listen 80;
    server_name _;
    access_log /var/log/nginx/simplemadetutor.access.log;
    error_log /var/log/nginx/simplemadetutor.error.log;
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /static {
        alias /home/implemad/www/simplemadetutor/app/static;
    }
    location /favicon.ico {
        alias /home/implemad/www/simplemadetutor/app/static/img/favicon.ico;
    }
}

问题是,如果我输入url_for('main.index', _external=True)而不是http://simplemadetutor.com,我会看到http://127.0.0.1:8000/

我尝试过设置SERVER_NAME =' simplemadetutor.com&#39 ;;然而,这似乎把simplemadetutor.com放在url_for extead生成的每个url前面,只有那些external = True。

0 个答案:

没有答案