【问题标题】:Add another site to my flask application on the same server在同一台服务器上向我的烧瓶应用程序添加另一个站点
【发布时间】:2017-04-25 10:48:58
【问题描述】:

所以我目前有sitea.com 设置,并且已经积极运行了一年多。现在我要加siteb.comsiteb.com也会有一个博客在上面,叫siteb.com/blog

有人可以帮帮我吗?

这是我当前的配置: app.py:

@app.route('/')
def home():
        '''
        home() will show the homepage of my website sitea.com
        '''
        return render_template('index.html')

问题是sitea.comsiteb.com 都指向同一个服务器,所以如果我尝试访问每个服务器,它只会拉出现有的sitea.com 站点,但我想使它基于通过烧瓶访问域名。

我该怎么做?我假设需要对烧瓶配置中现有的 sitea.com 进行更改,同时还要添加对 siteb.com 的更改。

谁能帮助我?

谢谢

【问题讨论】:

  • 这正是 Apache 和 nginx 等工具的用途
  • @JoranBeasley - 两个站点可以有完全相同的块吗?位置 / { proxy_pass localhost:8000; proxy_set_header 主机 $host; proxy_set_header X-Real-IP $remote_addr; }
  • 你可能想发布一个新的 Apache 问题,或者我真的会推荐 nginx
  • 我正在使用 nginx,这个块是否可能不会造成困难?

标签: python flask configuration


【解决方案1】:

一种可能的情况是,您拆分您的网站网址并在不同的域中呈现。喜欢:

@app.route('/')
      def home():
         # Return different results depending on the host
         url = split_url(request.url)
         if "www.sitea.com" == url['domain']:
             return "<h1>You are visiting sitea.com</h1><p>Here's your URL " +
     request.url + "</p>"
         else:
             return "<h1>You are not visiting www.sitea.com</h1><p>Here's your URL "
     + request.url + "</p>"

    def split_url(url):
         "Returns the full URL in two parts, the domain, and the path"
         url = url.split('/', 3)
         return {'domain': url[2], 'path': url[3]}

【讨论】:

  • 反正指定路线如@app.route('sitea.com') ?
猜你喜欢
  • 1970-01-01
  • 2019-09-10
  • 1970-01-01
  • 2020-07-06
  • 2013-03-05
  • 2012-03-10
  • 1970-01-01
  • 2015-01-14
  • 2014-02-23
相关资源
最近更新 更多