摆脱"appspot"在App Engine中我的应用程序域中 [英] Get rid of "appspot" in the domain of my app in App Engine

查看:55
本文介绍了摆脱"appspot"在App Engine中我的应用程序域中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Google上搜索了很多天.而且我仍然找不到正确的答案,所以我要问.

I've googled, read a lot for days. And I still can't get a proper answer, so I'm gonna ask.

我有一个自定义域,并添加了该域以通过App Engine部署我的应用.当我这样做时,App Engine还会创建同一应用程序的其他网址,例如:

I have a custom domain, and I added it to deploy my app with App Engine. When I do, App Engine also creates others urls of my same app, for example:

我的域名是example.com,在部署时,我有四个网站与我的网站相同:

My domain is example.com, when I deploy, I have four sites with my same website:

重要提示:我的ProjectID与我购买的域的名称相同

  • example.com(和www.example.com)
  • example.appspot.com
  • staging.example.appspot.com
  • us.artifacts.example.appspot.com

那么,我怎么能杀死所有那些不必要的网址,而只留在www.example.com和example.com上呢?

So, how could I kill all those unnecessary urls and only stay with www.example.com and example.com?

((我当时在考虑使用Express.js来处理此问题,但我首先想知道是否有更好的最终解决方案.我也尝试过使用它配置dispatch.yaml文件,但似乎没有并使用.htaccess文件发送301,但App Engine无法识别此内容,因为它不是Apache服务器.).

(I was thinking of using Express.js to handle this, but I first would like to know if there's a better final solution. I've also tried configuring the dispatch.yaml file with it but it doesn't seem to work on this, and also with a .htaccess file to send 301 but App Engine doesn't recognize this since it's not an Apache server).

复制并检查如何防止"appspot.com"我的App Engine应用程序?

DUPLICATED, CHECK How do I prevent the "appspot.com" of my App Engine app?

推荐答案

无法从App Engine上的任何应用程序中删除 appspot.com 域.

There is no way to delete the appspot.com domains from any application on App Engine.

如果您真的想摆脱它们",或者根本无法访问它们,则可以从应用程序上的传入请求中读取Host标头,然后检查该请求是否是发给appspot.com或到您的自定义域(这是在您的应用程序级别完成的,大多数框架都应允许您这样做).

If you really want to "get rid of them", or making them not accessible at all, you can probably read the Host header from incoming requests on the application, and then check if the request was made to appspot.com or to your custom domain (this is done at your application level, most frameworks should allow you to do it).

然后,您可以重定向请求,或仅返回错误响应,或完全不执行任何操作.

Then you can redirect the request, or just return an error response, or nothing at all.

例如,使用烧瓶,您可以执行以下操作:

For example, with flask you can do the following:

from flask import Flask, request, redirect

app = Flask(__name__)

@app.route('/')
def read_host():
    host = request.host
    if "appspot.com" in host:
        return redirect('https://[CUSTOM-DOMAIN].com', code=301)

    # else, keep running the application normally, it means that the request
    # was made to the Custom Domain

if __name__=='__main__':
    app.run('127.0.0.1', port=8080, debug=True)

请问您为什么对此感兴趣?据我所知,当appspot域与自定义域共存时,应该不会有任何冲突或问题,而且也不会因为拥有这些appspot域名而向您收费.

Can I ask why are you interested on doing this? As far as I know there should be no conflict or issues when the appspot domains are coexisting with custom domains, and you are not getting billed for having these appspot domain names either.

这篇关于摆脱"appspot"在App Engine中我的应用程序域中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆