Google App Engine: 404 Not Found with Custom Domain - google-app-engine

I setup a Flask app on Google App Engine as a Flex project.
When I browse to https://{project-id}.appspot.com everything is working fine and I can use the app without a problem. Why am I getting a 404?
I setup a custom domain as host.mydomain.io
gcloud beta app domain-mappings list
ID SSL_CERTIFICATE_ID SSL_MANAGEMENT_TYPE
host.mydomain.io 5270000 AUTOMATIC
Then I setup my dns to point to ghs.googlehosted.com
nslookup host.mydomain.io
Non-authoritative answer:
host.mydomain.io canonical name = ghs.googlehosted.com.
Name: ghs.googlehosted.com
Address: 172.217.0.115
However I always get a 404 and here are the logs
gcloud app logs tail -s default
2018-01-25 03:06:32 default[20180124t211951] "GET /" 404
2018-01-25 03:06:36 default[20180124t211951] "GET /" 404
Yet when I browse using the https://{project-id}.appspot.com address it works fine
2018-01-25 02:31:55 default[20180124t211951] "GET /" 200
app.yaml
entrypoint: 'gunicorn manage:app -w 4 -b :$PORT'
env: flex
runtime: python
env_variables:
FLASK_CONFIG: "production"

I found the problem was coming from my Flask configuration and not from Google App Engine
In my Production configuration I had this:
SERVER_NAME = "{project-id}.appspot.com"
This was causing Flask to return the 404 , not App Engine.
Changing it to
SERVER_NAME = "hostname.mydomain.io"
Fixed it for me.

Related

Problem during deploying Metabase with Google App Engine

I am following this instructions for deploying metabase with Google App Engine, after I complete the operations and open the url where the service is deployed i get 502 Bad Gateway or
Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds. and from console I got
INFO metabase.driver :: Registered abstract driver :sql ?
This is my app.yaml
env: flex
manual_scaling:
instances: 1
env_variables:
MB_JETTY_PORT: 8080
MB_DB_TYPE: postgres
MB_DB_DBNAME: metabase
MB_DB_PORT: 5432
MB_DB_USER: devops
MB_DB_PASS: password
MB_DB_HOST: 127.0.0.1
beta_settings:
cloud_sql_instances: <instance-name>=tcp:5432
Dockerfile:
FROM gcr.io/google-appengine/openjdk
EXPOSE 8080
ENV PORT 8080
ENV MB_PORT 8080
ENV MB_JETTY_PORT 8080
ENV MB_DB_PORT 5432
ENV METABASE_SQL_INSTANCE <instance_name>=tcp:5432
ENV JAVA_OPTS "-XX:+IgnoreUnrecognizedVMOptions -Dfile.encoding=UTF-8 --add-opens=java.base/java.net=ALL-UNNAMED --add-modules=java.xml.bind"
ADD https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 ./cloud_sql_proxy
ADD http://downloads.metabase.com/v0.33.2/metabase.jar /metabase.jar
RUN chmod +x ./cloud_sql_proxy
CMD ./cloud_sql_proxy -instances=$METABASE_SQL_INSTANCE=tcp:$MB_DB_PORT & java -jar ./metabase.jar
Also I troubleshoot everything I saw on stackoverflow and tried all options with similar problem but still not working, i tried this option 1 and this options 2 but still no working effects.
My steps:
On GCP I am the owner of the project,I created Compute engine VM instance, then SQL Postgres instance, and a new Postgres database with user, I added the public IP address of the VM in the configurations of the SQL Instance as authorized network, and deployed the app.yaml and Dockerfile with gcloud app deploy. Any working solutons?
[1]: https://www.cloudbooklet.com/install-metabase-on-google-cloud-with-docker-app-engine/
I fixed the issue. I just change the metabase version, it always has to be the newest. 0.36.6 at this moment

Laravel Project work perfect on localhost and Response with error 500 on GAE

I'm fairly new to working with live projects.
My project runs perfectly on localhost, I deploy the exact same copy to google app engine using the command gcloud beta app deploy.
My welcome page works perfectly:
As Well as my auth pages:
straight after the auth process i get the following response:
To verify that the account has been authenticated my route url is redirecting to the dashboard:
example.com/admin/users
my app.yaml file is as follows:
runtime: php
env: flex
runtime_config:
document_root: public
# Ensure we skip ".env", which is only for local development
skip_files:
- .env
env_variables:
# Put production environment variables here.
APP_LOG: errorlog
APP_KEY: App-key
STORAGE_DIR: /tmp
CACHE_DRIVER: file
SESSION_DRIVER: file
## Set these environment variables according to your CloudSQL configuration.
DB_HOST: localhost
DB_DATABASE: lara
DB_USERNAME: root
DB_PASSWORD: password
DB_SOCKET: /cloudsql/connection-name
MAIL_MAILER: smtp
MAIL_HOST: smtp.mailtrap.io
MAIL_PORT: 2525
MAIL_USERNAME:username
MAIL_PASSWORD: password
MAIL_FROM_ADDRESS: from#example.com
MAIL_FROM_NAME: {App-Name}
#we need this for the flex environment
beta_settings:
# for Cloud SQL, set this value to the Cloud SQL connection name,
cloud_sql_instances: connection-name
Here is my log?
This is the view it is looking for:
My routes:
It's funny how small things create the biggest issues, took me over 3 weeks to resolve this issue.
As I was conducting research I discovered that Google App engine is case sensitive and so here are steps I used to resolve this issue:
1st I checked my routes using php artisan route:list and my route is route: admin.users.index and my file structure was --path: views/Admin/Users/index.blade.php and so i change all my folders to lower-case to match the route.
Then I ran the following commands:
php artisan cache:clear
php artisan route:clear
php artisan view:clear
Lastly I added the following script under scripts on my composer.json file:
"post-install-cmd": [
"chmod -R 755 bootstrap\/cache",
"php artisan cache:clear"
]
Deployed using gcloud app deploy
Worked like a charm.

502 Bad Gateway Nginx error while deploying Django Channels app using Daphne on Google App Engine (Flexible)

My Django app was working fine on Google App Engine (Flexible) using gunicorn as entrypoint in the app.yaml file. I needed to add websockets to it so I used Django Channels (with redis). This works beautifully on my local machine (Windows 10).
For deployment, I changed my entrypoint to daphne on port 8080 since that's the default on GAE (using $PORT produces the same effect), so my yaml file now looks like this:
runtime: python
env: flex
runtime_config:
python_version: 3
entrypoint: daphne -b 127.0.0.1 -p 8080 my_project_name.asgi:application
I've checked my .asgi file and requirements.txt to ensure everything is ok and the packages are the latest versions.
But after deploying it, I get a "502 Bad Gateway Nginx" error.
The Stackdriver logs (nginx.error) on the GCP cloud console say the below:
[error] 33#33: *341 connect() failed (111: Connection refused) while connecting
to upstream, client: 172.xxx.xxx.xxx, server: , request: "GET / HTTP/1.1",
upstream: "172.17.0.1:8080", host: "my_project_name.appspot.com"
I don't recognize those IPs for upstream server or client, and I don't know what to do next. I've tried numerous things over the last 4 days, including:
using various different ports (8000, 8001 etc)
adding an nginx.conf file (based on this documentation) in my project directory, which seems to make no difference
Adding a line in the runtime_config section of the yaml file that says "nginx_conf_http_include: nginx.conf"
4.Using Unix sockets to start the daphne server in the entrypoint like "entrypoint: daphne -u /tmp/daphne.sock my_project_name.asgi:application
Deleting the entrypoint altogether after declaring the daphne server in the nginx.conf file
None of this helps. The logs stay the same, the error stays the same. I've read SO questions like this and this but I don't know how to apply them to GAE Flex since I'm not directly operating the VM instance. Please help.

deploying tornado on Google App Engine

I am trying to deploy my python pricing module which takes product details (string) as argument, on to GAE. The tornado wrapper is working fine on localhost (localhost:8888/?q=) but giving server error 500 on GAE.
Code in Pricing-OOP.py file:
class MainHandler(tornado.web.RequestHandler):
def get(self):
q = self.get_query_argument("q")
res = Pricing(q).pricing()
self.write(json.dumps(res))
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
],debug=True)
if __name__ == '__main__':
Pickleload()
app = make_app()
container = tornado.wsgi.WSGIContainer(app)
http_server = tornado.httpserver.HTTPServer(container)
http_server.listen(8888)
tornado.ioloop.IOLoop.current().start()
app.yaml file:
service: tornado
runtime: python27
threadsafe: no
handlers:
- url: /.*
script: Pricing-OOP.py
The gcloud app logs tail is as follows:
2017-07-26 03:03:30 tornado[20170726t082447] "GET / HTTP/1.1" 500
2017-07-26 03:03:30 tornado[20170726t082447] "GET /favicon.ico HTTP/1.1" 500
2017-07-26 03:03:33 tornado[20170726t082447] "GET / HTTP/1.1" 500
2017-07-26 03:03:34 tornado[20170726t082447] "GET /favicon.ico HTTP/1.1" 500
How do I correct this?
There are a few notes regarding deploying on Google App Engine in the Tornado docs.
In particular, a Tornado application on GAE must be run as a WSGI application. You cannot do things like open ports on the local machine,
and unfortunately it also prevents the use of asynchronous aspects of Tornado (which are often the main driver for using it in the first place).
In your case, instead of creating the HttpServer yourself, you should just create the WSGIAdapter:
# Pricing-OOP.py
# ...
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
],debug=False)
application = make_app()
application = tornado.wsgi.WSGIAdapter(application)
You then tell GAE where to find application by referencing it in the script directive of your configuration file:
# app.yaml
# ...
handlers:
- url: /.*
script: Pricing-OOP.application
Because you are now a "pure" WSGI application, you need to run it in a container. The Google Cloud SDK includes a development server in dev_appserver.py that can be used to host your app:
$ dev_appserver.py . # in directory containing app.yaml
That being done, you can run the same application code both locally and in your GAE instance.

Issues while creating and deploying an app to google app engine

I am running into this error while deploying my app to google app-engine.
Error:
Error 404: --- begin server output ---
This application does not exist (project_id=u'homework-153002'). To create an App Engine application in this project, run "gcloud beta app create" in your console.
--- end server output ---
When I try to create the app using the above command this is what I see:
ERROR: (gcloud.beta.app.create) You do not have permission to access app [homework] (or it may not exist): Operation not allowed
I have created a project in google developers api website with project_name of "homework" and random id. Here is the url for that:
https://console.developers.google.com/apis/library?project=homework-153002
Any pointers on what I might be doing wrong here?
This is my yaml file:
application: homework-153002
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
Your app URL indicates your app ID is homework-153002, but the
error message indicates you're connecting to an ap called homework - likely not your own, hence the permission issue.
Simply correcting the app ID in your deployment command and/or your app.yaml file should suffice.
As your comment indicates, for your case (gcloud deployment) the solution was:
gcloud config set project homework-153002
gcloud beta app create
appcfg.py update homework/

Resources