I've deployed my flask app on heroku, and i'm getting "Method not allowed" in my browser at the url.
all my routes have the methods set. I'm not trying to do much other than access my pages (no forms or anything like that). I'm using gunicorn. Just got no idea where I'm going wrong.
here is my main file:
from mongo import get_spotify_music
import os
app = Flask(__name__)
music = list(get_spotify_music())
#app.route("/", methods=['GET'])
#app.route("/index", methods=['GET'])
def home():
return render_template('index.html', title='about')
is_live = os.environ.get("IS_LIVE", None)
url = '0.0.0.0' if is_live else '127.0.0.1'
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host=url, port=port, debug=True)```
my Procfile looks like:
```web: gunicorn app:app```
heroku logs --tail looks like:
```2019-07-15T08:25:41.093957+00:00 app[api]: Deploy 325e5224 by user myemail#myemail.com
2019-07-15T08:25:45.035819+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2019-07-15T08:25:47.166897+00:00 app[web.1]: [2019-07-15 08:25:47 +0000] [4] [INFO] Starting gunicorn 19.9.0
2019-07-15T08:25:47.167484+00:00 app[web.1]: [2019-07-15 08:25:47 +0000] [4] [INFO] Listening at: http://0.0.0.0:57502 (4)
2019-07-15T08:25:47.167616+00:00 app[web.1]: [2019-07-15 08:25:47 +0000] [4] [INFO] Using worker: sync
2019-07-15T08:25:47.172768+00:00 app[web.1]: [2019-07-15 08:25:47 +0000] [10] [INFO] Booting worker with pid: 10
2019-07-15T08:25:47.261871+00:00 app[web.1]: [2019-07-15 08:25:47 +0000] [11] [INFO] Booting worker with pid: 11
2019-07-15T08:25:47.852647+00:00 heroku[web.1]: State changed from starting to up
2019-07-15T08:25:50.000000+00:00 app[api]: Build succeeded
When I go to the link that's set, i just get a method not allowed, rather than my web page....
Not sure where I'm going wrong here...
Related
I tried to deploy very simple Flask application:
import flask
app = flask.Flask(__name__)
#app.route('/', methods=['GET'])
def home():
return '<h1>Hello!</h1></p>'
app.run()
I followed some official tutorials, created App Service in Azure Portal, deployed app using Local Git solution. Application is deployed, but when I try to browse it, I get:
:( Application Error. If you are the application administrator, you can access the diagnostic resources.
My logs:
2022-09-22T14:24:17.032341362Z
2022-09-22T14:24:17.032431764Z _____
2022-09-22T14:24:17.032440964Z / _ \ __________ _________ ____
2022-09-22T14:24:17.032445564Z / /_\ \___ / | \_ __ \_/ __ \
2022-09-22T14:24:17.032449964Z / | \/ /| | /| | \/\ ___/
2022-09-22T14:24:17.032454364Z \____|__ /_____ \____/ |__| \___ >
2022-09-22T14:24:17.032458965Z \/ \/ \/
2022-09-22T14:24:17.032463265Z
2022-09-22T14:24:17.032467265Z A P P S E R V I C E O N L I N U X
2022-09-22T14:24:17.032471165Z
2022-09-22T14:24:17.032474965Z Documentation: http://aka.ms/webapp-linux
2022-09-22T14:24:17.032489065Z Python 3.9.7
2022-09-22T14:24:17.032493765Z Note: Any data outside '/home' is not persisted
2022-09-22T14:24:17.180055832Z Starting OpenBSD Secure Shell server: sshd.
2022-09-22T14:24:17.215008000Z App Command Line not configured, will attempt auto-detect
2022-09-22T14:24:17.433349825Z Starting periodic command scheduler: cron.
2022-09-22T14:24:17.442192344Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite
2022-09-22T14:24:17.556237878Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2022-09-22T14:24:17.562671538Z Output is compressed. Extracting it...
2022-09-22T14:24:17.564241977Z Build Operation ID: |OgP/jQgIHgU=.1da790b7_
2022-09-22T14:24:17.564259877Z Oryx Version: 0.2.20220825.1, Commit: 24032445dbf7bf6ef068688f1b123a7144453b7f, ReleaseTagName: 20220825.1
2022-09-22T14:24:17.565391205Z Extracting '/home/site/wwwroot/output.tar.gz' to directory '/tmp/8da9ca604221f20'...
2022-09-22T14:24:18.725265722Z App path is set to '/tmp/8da9ca604221f20'
2022-09-22T14:24:19.018530608Z Detected an app based on Flask
2022-09-22T14:24:19.405035911Z Generating `gunicorn` command for 'index:app'
2022-09-22T14:24:19.456995902Z Writing output script to '/opt/startup/startup.sh'
2022-09-22T14:24:19.689506779Z Using packages from virtual environment antenv located at /tmp/8da9ca604221f20/antenv.
2022-09-22T14:24:19.690332099Z Updated PYTHONPATH to ':/opt/startup/app_logs:/opt/startup/code_profiler:/tmp/8da9ca604221f20/antenv/lib/python3.9/site-packages'
2022-09-22T14:24:20.556171311Z [2022-09-22 14:24:20 +0000] [77] [INFO] Starting gunicorn 20.1.0
2022-09-22T14:24:20.595370385Z [2022-09-22 14:24:20 +0000] [77] [INFO] Listening at: http://0.0.0.0:8000 (77)
2022-09-22T14:24:20.601700442Z [2022-09-22 14:24:20 +0000] [77] [INFO] Using worker: sync
2022-09-22T14:24:20.610324257Z [2022-09-22 14:24:20 +0000] [80] [INFO] Booting worker with pid: 80
2022-09-22T14:24:21.265168226Z * Serving Flask app 'index'
2022-09-22T14:24:21.266054348Z * Debug mode: on
2022-09-22T14:24:21.300157595Z [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
2022-09-22T14:24:21.300272498Z * Running on http://127.0.0.1:5000
2022-09-22T14:24:21.301268023Z [33mPress CTRL+C to quit[0m
2022-09-22T14:24:21.308547204Z * Restarting with stat
2022-09-22T14:24:21.760007120Z [2022-09-22 14:24:21 +0000] [81] [INFO] Starting gunicorn 20.1.0
2022-09-22T14:24:21.772788238Z [2022-09-22 14:24:21 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2022-09-22T14:24:21.773676260Z [2022-09-22 14:24:21 +0000] [81] [ERROR] Retrying in 1 second.
2022-09-22T14:24:22.779581652Z [2022-09-22 14:24:22 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2022-09-22T14:24:22.780698179Z [2022-09-22 14:24:22 +0000] [81] [ERROR] Retrying in 1 second.
2022-09-22T14:24:23.781856453Z [2022-09-22 14:24:23 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2022-09-22T14:24:23.783124685Z [2022-09-22 14:24:23 +0000] [81] [ERROR] Retrying in 1 second.
2022-09-22T14:24:24.787329534Z [2022-09-22 14:24:24 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2022-09-22T14:24:24.788615966Z [2022-09-22 14:24:24 +0000] [81] [ERROR] Retrying in 1 second.
2022-09-22T14:24:25.792686075Z [2022-09-22 14:24:25 +0000] [81] [ERROR] Connection in use: ('0.0.0.0', 8000)
2022-09-22T14:24:25.794038102Z [2022-09-22 14:24:25 +0000] [81] [ERROR] Retrying in 1 second.
2022-09-22T14:24:26.795751866Z [2022-09-22 14:24:26 +0000] [81] [ERROR] Can't connect to ('0.0.0.0', 8000)
2022-09-22T14:24:26.839176431Z [2022-09-22 14:24:26 +0000] [80] [INFO] Worker exiting (pid: 80)
2022-09-22T14:24:26.928820618Z [2022-09-22 14:24:26 +0000] [84] [INFO] Booting worker with pid: 84
It happens all the time, starting, problem with port, restarting, again and again. As I said, I just followed tutorials, didn't change any port or IP address...
I found a solution. My code was development version - in logs was a warning:
WARNING: This is a development server. Do not use it in a production
deployment. Use a production WSGI server instead
I changed code as was answered in Flask at first run: Do not use the development server in a production environment :
import flask
app = flask.Flask(__name__)
#app.route('/', methods=['GET'])
def home():
return '<h1>Hello!</h1></p>'
# debug app:
# app.run()
if __name__ == "__main__":
from waitress import serve
serve(app, host="0.0.0.0", port=8080)
Now application is deployed to Azure and working properly.
I am running a Flask app on a Ubuntu Linode Server using Gunicorn to serve the app and nginx as a reverse proxy.
I have one app running successfully, but I have a second app where I'm running in to the following problem.
What does work
when I run FLASK_APP=tester.py python3 -m flask run
This works, tester.py runs the app bound to 0.0.0.0 on port 5100 and I can access it from my browser.
when I run gunicorn --bind 0.0.0.0:5100 wsgi:app
This also works, as my wsgi.py imports my app object making it accessible for wsgi
Useful details
which python gives me /usr/bin/python
which pip gives /usr/bin/pip and which pip3 gives /usr/bin/pip3
which python3 gives me /usr/bin/python3
which gunicorn gives me /usr/bin/gunicorn
I am not using a virtual environment since boths app have near identical dependencies
What's not working
I created a service for forwarding traffic with nginx with:
/etc/systemd/system/testpad.service
[Unit]
# specifies metadata and dependencies
Description=Gunicorn instance to serve myproject
After=network.target
# tells the init system to only start this after the networking target has been reached
# We will give our regular user account ownership of the process since it owns all of the relevant files
[Service]
# Service specify the user and group under which our process will run.
User=www-data
# give group ownership to the www-data group so that Nginx can communicate easily with the Gunicorn processes.
Group=www-data
# We'll then map out the working directory and set the PATH environmental variable so that the init system knows where our the executabl>
WorkingDirectory=/home/xxx/xxx
# We'll then specify the commanded to start the service
ExecStart=/usr/bin/gunicorn --bind unix:testpad.sock --access-logfile /home/xxx/xxx/accesslog --error-logfile /home/xxx/xxx/errorlog -m 007 wsgi:app
# This will tell systemd what to link this service to if we enable it to start at boot. We want this service to start when the regular m>
[Install]
WantedBy=multi-user.target
when I start the service it runs for a second then I get this from sudo systemctl status testpad
testpad.service - Gunicorn instance to serve myproject
Loaded: loaded (/etc/systemd/system/testpad.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2021-09-06 15:47:59 UTC; 16min ago
Process: 655575 ExecStart=/usr/bin/gunicorn --bind unix:testpad.sock --access-logfile /home/xxx/xxx/acces>
Main PID: 655575 (code=exited, status=1/FAILURE)
Sep 06 15:47:54 microportalbeta systemd[1]: Started Gunicorn instance to serve myproject.
Sep 06 15:47:59 microportalbeta systemd[1]: testpad.service: Main process exited, code=exited, status=1/FAILURE
Sep 06 15:47:59 microportalbeta systemd[1]: testpad.service: Failed with result 'exit-code'.
so when I cat errorlog I get
[2021-09-06 15:21:31 +0000] [655222] [INFO] Worker exiting (pid: 655222)
[2021-09-06 15:21:31 +0000] [655223] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 384, in import_app
mod = importlib.import_module(module)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/xxx/xxx/wsgi.py", line 1, in <module>
from run import app
File "/home/xxx/xxx/run.py", line 1, in <module>
from genedflask import create_app, db
File "/home/xxx/xxx/xxx/__init__.py", line 5, in <module>
from flask_login import LoginManager
ModuleNotFoundError: No module named 'flask_login'
[2021-09-06 15:21:31 +0000] [655223] [INFO] Worker exiting (pid: 655223)
[2021-09-06 15:21:32 +0000] [655220] [WARNING] Worker with pid 655223 was terminated due to signal 15
[2021-09-06 15:21:32 +0000] [655220] [WARNING] Worker with pid 655222 was terminated due to signal 15
[2021-09-06 15:21:32 +0000] [655220] [INFO] Shutting down: Master
[2021-09-06 15:21:32 +0000] [655220] [INFO] Reason: Worker failed to boot.
[2021-09-06 15:23:34 +0000] [655249] [INFO] Starting gunicorn 20.1.0
[2021-09-06 15:23:34 +0000] [655249] [ERROR] Retrying in 1 second.
[2021-09-06 15:23:35 +0000] [655249] [ERROR] Retrying in 1 second.
[2021-09-06 15:23:36 +0000] [655249] [ERROR] Retrying in 1 second.
[2021-09-06 15:23:37 +0000] [655249] [ERROR] Retrying in 1 second.
[2021-09-06 15:23:38 +0000] [655249] [ERROR] Retrying in 1 second.
[2021-09-06 15:23:39 +0000] [655249] [ERROR] Can't connect to testpad.sock
[2021-09-06 15:28:44 +0000] [655315] [INFO] Starting gunicorn 20.1.0
[2021-09-06 15:28:44 +0000] [655315] [ERROR] Retrying in 1 second.
[2021-09-06 15:28:45 +0000] [655315] [ERROR] Retrying in 1 second.
[2021-09-06 15:28:46 +0000] [655315] [ERROR] Retrying in 1 second.
[2021-09-06 15:28:47 +0000] [655315] [ERROR] Retrying in 1 second.
[2021-09-06 15:28:48 +0000] [655315] [ERROR] Retrying in 1 second.
[2021-09-06 15:28:49 +0000] [655315] [ERROR] Can't connect to testpad.sock
[2021-09-06 15:31:09 +0000] [655348] [INFO] Starting gunicorn 20.1.0
[2021-09-06 15:31:09 +0000] [655348] [ERROR] Retrying in 1 second.
[2021-09-06 15:31:10 +0000] [655348] [ERROR] Retrying in 1 second.
[2021-09-06 15:31:11 +0000] [655348] [ERROR] Retrying in 1 second.
[2021-09-06 15:31:12 +0000] [655348] [ERROR] Retrying in 1 second.
[2021-09-06 15:31:13 +0000] [655348] [ERROR] Retrying in 1 second.
[2021-09-06 15:31:14 +0000] [655348] [ERROR] Can't connect to testpad.sock
[2021-09-06 15:33:34 +0000] [655387] [INFO] Starting gunicorn 20.1.0
[2021-09-06 15:33:34 +0000] [655387] [ERROR] Retrying in 1 second.
[2021-09-06 15:33:35 +0000] [655387] [ERROR] Retrying in 1 second.
[2021-09-06 15:33:36 +0000] [655387] [ERROR] Retrying in 1 second.
[2021-09-06 15:33:37 +0000] [655387] [ERROR] Retrying in 1 second.
[2021-09-06 15:33:38 +0000] [655387] [ERROR] Retrying in 1 second.
[2021-09-06 15:33:39 +0000] [655387] [ERROR] Can't connect to testpad.sock
[2021-09-06 15:47:54 +0000] [655575] [INFO] Starting gunicorn 20.1.0
[2021-09-06 15:47:54 +0000] [655575] [ERROR] Retrying in 1 second.
[2021-09-06 15:47:55 +0000] [655575] [ERROR] Retrying in 1 second.
[2021-09-06 15:47:56 +0000] [655575] [ERROR] Retrying in 1 second.
[2021-09-06 15:47:57 +0000] [655575] [ERROR] Retrying in 1 second.
[2021-09-06 15:47:58 +0000] [655575] [ERROR] Retrying in 1 second.
[2021-09-06 15:47:59 +0000] [655575] [ERROR] Can't connect to testpad.sock
Not sure why it is not finding flask-login as it is installed under pip and pip3 globally, and is visible when I run pip3 list or pip list.
I assume that once I overcome this hurdle then the testpad.sock file should auto create as it did with my previous app. Most people with this problem I found it was an issue with gunicorn looking at the global environment when people installed dependencies in a virtual environment, which I am not doing in this circumstance.
Any suggestions?
Update
I never did figure out why it could not find the libraries when ran as a service, I even set the PYTHONPATH variable to see if that would help.
What I did do is give up on running as a service and instead just ran the application as a background process on port 8000 and just directed nginx to forward traffic there, and that worked.
heroku logs
2018-04-20T20:45:50.151330+00:00 app[api]: Enable Logplex by user ghsklat2378123#gmail.com
2018-04-20T20:45:50.059558+00:00 app[api]: Release v1 created by user ghsklat2378123#gmail.com
2018-04-20T20:45:50.059558+00:00 app[api]: Initial release by user ghsklat2378123#gmail.com
2018-04-20T20:45:50.151330+00:00 app[api]: Release v2 created by user ghsklat2378123#gmail.com
2018-04-20T20:46:48.000000+00:00 app[api]: Build started by user ghsklat2378123#gmail.com
2018-04-20T20:46:58.098188+00:00 app[api]: Deploy 2b289e67 by user ghsklat2378123#gmail.com
2018-04-20T20:46:58.098188+00:00 app[api]: Release v3 created by user ghsklat2378123#gmail.com
2018-04-20T20:46:48.000000+00:00 app[api]: Build succeeded
2018-04-20T20:46:58.115335+00:00 app[api]: Scaled to web#1:Free by user ghsklat2378123#gmail.com
2018-04-20T20:47:00.895268+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-20T20:47:03.518908+00:00 app[web.1]:
2018-04-20T20:47:03.518933+00:00 app[web.1]: > node server.js
2018-04-20T20:47:03.518931+00:00 app[web.1]: > stywqrrd#1.0.0 start /app
2018-04-20T20:47:03.518935+00:00 app[web.1]:
2018-04-20T20:47:03.875652+00:00 app[web.1]: Express server listening on port 3000
2018-04-20T20:48:01.013365+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-04-20T20:48:01.013866+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-04-20T20:48:01.152301+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-20T20:48:01.155261+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-20T20:48:01.132422+00:00 heroku[web.1]: Process exited with status 137
2018-04-20T20:48:02.894892+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-20T20:48:05.106690+00:00 app[web.1]:
2018-04-20T20:48:05.106708+00:00 app[web.1]: > sstywqrrd#1.0.0 start /app
2018-04-20T20:48:05.106710+00:00 app[web.1]: > node server.js
2018-04-20T20:48:05.106712+00:00 app[web.1]:
2018-04-20T20:48:05.295340+00:00 app[web.1]: Express server listening on port 3000
This is a very simple node app that i'm unable to deploy. When I got the link it displays:heroku welcome to you new app. Refer to documentation if you need help deploying. Logs don't show any error(all logs shown in blue color). How do I solve this?
Cloned the repo and then did
git init, git add, git commit
heroku create
heroku git:remote -a safe-forest-59278
heroku apps:create myappName
git push heroku master
According to log statement
Error R10 (Boot timeout) -> Web process failed to bind to $PORT
within 60 seconds of launch
This simply means that the port your are trying to connect with is not available for some reason.
And most probably you're specifying the port like
port = 3000
You should change this line to
port = process.env.PORT || 3000
This will let heroku servers to assign an available port to your server to listen to.
Why this happens is because mostly the ports that you specify while developing an application, there are very rare chances for that ports to be available and open in production.
Here is an issue I am having with an app on Parse-Server (/Heroku).
I keep getting the message:
WARNING, Unable to connect to 'https://myapp.herokuapp.com/'. Cloud code and push notifications may be unavailable!
Here is the complete log I have when running the command: git push heroku master
2018-02-2...+00:00 app[api]: Build started by user me#xyz.com
2018-02-2...+00:00 app[api]: Deploy bduxedc8 by user me#xyz.com
2018-02-2...+00:00 app[api]: Build succeeded
2018-02-2...+00:00 app[api]: Release v25 created by user me#xyz.com
2018-02-2...+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-02-2...+00:00 heroku[web.1]: Process exited with status 143
2018-02-2...+00:00 heroku[web.1]: Restarting
2018-02-2...+00:00 heroku[web.1]: State changed from up to starting
2018-02-2...+00:00 heroku[web.1]: Starting process with command `npm start`
2018-02-2...+00:00 app[web.1]:
2018-02-2...+00:00 app[web.1]: > parse-server-example#1.4.0 start /app
2018-02-2...+00:00 app[web.1]: > node index.js
2018-02-2...+00:00 app[web.1]:
2018-02-2...+00:00 app[web.1]: parse-server-example running on port 23377.
2018-02-2...+00:00 heroku[web.1]: State changed from starting to up
2018-02-2...+00:00 heroku[router]: at=info method=GET path="/health" host=myapp.herokuapp.com request_id=fb429287-9b14-4373-97ab-30dac19a4db7 fwd="1.2.3.438" dyno=web.1 connect=2ms service=20ms status=404 bytes=217 protocol=https
2018-02-28T04:03:21.595649+00:00 app[web.1]:
2018-02-28T04:03:21.595660+00:00 app[web.1]: WARNING, Unable to connect to 'https://myapp.herokuapp.com/'. Cloud code and push notifications may be unavailable!
2018-02-28T04:03:21.595663+00:00 app[web.1]:
And if I change https to http in my configuration, I see exactly the same behavior.
Beside if I try to access to https://myapp.herokuapp.com/ in a browser I can do it with no problem.
I have read many post on the issue but nothing drove me to a solution.
That would be great if someone could let me know how to solve this.
I faced this issue and it might help someone in the future.
Note that this is one of the reasons why this warning might be thrown.
This is for parse server version: 2.8.2
To create your own standalone parse server, using express, the basic steps involved are close to:
Create a parse-server object with all your config like. For example: const api = new ParseServer(config);
config will contain the server URL along with all other requirements.
Create an express app object. For example: const app = express();
Then mount the parse server API on the express like -> app.use(mountPath, api);
And then create the server like: const httpServer = require('http').createServer(app);
And then start listening on a port like: httpServer.listen(port);
As soon as the mount is called, the parse-server will verify the url mentioned in the config by making a request to /health endpoint.
If for some reason there is a delay in listening to the port (point 6) after mounting the API (point 4), then the above warning will be thrown.
For example, in one case I was establishing a mongoose connection and only then started listening to the port. Because of this, the verification of URL from parse server failed, although everything worked fine after that.
And one of the possible solutions is to get done with all such work before mounting the parse API and ensuring no delay between mounting and listening to the port as described above.
While this may not be the exact steps for creating a parse server on heroku, the idea is that:
parse server will call verify url on the server url mentioned in the configs.
And if there is delay in starting the server after you have mouted the parse apis, the above warning will be thrown.
2018-02-2...+00:00 heroku[router]: at=info method=GET path="/health" host=myapp.herokuapp.com request_id=fb429287-9b14-4373-97ab-30dac19a4db7 fwd="1.2.3.438" dyno=web.1 connect=2ms service=20ms status=404 bytes=217 protocol=https
Notice status is 404, this doesn't exist, and the host says myapp.herokuapp.com
Do you perhaps have a server_url key set to literally myapp.heroku.com, or did you redact the name of your app?
I am trying to serve a simple API by following this digitalocean tutorial.
For testing I was earlier serving the API through gunicorn by doing a
$ gunicorn --bind 0.0.0.0:5000 trumporate.wsgi:app
And curling the API endpoint works inside the ec2 box
$ curl -X GET http://0.0.0.0:5000/api/v1/trump/rant/
{
"foo": "bar"
}
Now I shifted this gunicorn process to run at startup by making a systemd service
# /etc/systemd/system/trumporate.service
[Unit]
Description=Gunicorn instance for trumporate
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/var/opt/trumporate
ExecStart=/usr/local/bin/gunicorn --workers 3 --bind unix:trumporate.sock -m 007 --access-logfile /var/log/trumporate/gunicorn-access.log --error-logfile /var/log/trumporate/gunicorn-error.log trumporate.wsgi:app
[Install]
WantedBy=multi-user.target
I have created the files
/var/log/trumporate/gunicorn-error.log
/var/log/trumporate/gunicorn-access.log
and changed the ownership and group to ubuntu
After enabling the service and rebooting, I checked the status
$ sudo systemctl status trumporate.service
● trumporate.service - Gunicorn instance for trumporate
Loaded: loaded (/etc/systemd/system/trumporate.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-05-03 06:30:26 UTC; 1h 2min ago
Main PID: 1122 (gunicorn)
Tasks: 4
Memory: 92.2M
CPU: 1.390s
CGroup: /system.slice/trumporate.service
├─1122 /usr/bin/python3 /usr/local/bin/gunicorn --workers 3 --bind unix:trumporate.sock -m 007 --access-logfile /var/log/trumporate/gunicorn-access.log --error-logfile /var/log/trumporate/gunic
├─1264 /usr/bin/python3 /usr/local/bin/gunicorn --workers 3 --bind unix:trumporate.sock -m 007 --access-logfile /var/log/trumporate/gunicorn-access.log --error-logfile /var/log/trumporate/gunic
├─1266 /usr/bin/python3 /usr/local/bin/gunicorn --workers 3 --bind unix:trumporate.sock -m 007 --access-logfile /var/log/trumporate/gunicorn-access.log --error-logfile /var/log/trumporate/gunic
└─1267 /usr/bin/python3 /usr/local/bin/gunicorn --workers 3 --bind unix:trumporate.sock -m 007 --access-logfile /var/log/trumporate/gunicorn-access.log --error-logfile /var/log/trumporate/gunic
May 03 06:30:26 ip-172-31-25-173 systemd[1]: Started Gunicorn instance for trumporate.
Following the DO tutorial, I tried configuring nginx to proxy incoming requests on port 80
$ cat /etc/nginx/sites-available/trumporate
server {
listen 80;
server_name private_ip_address;
location / {
include proxy_params;
proxy_pass http://unix:/var/opt/trumporate/trumporate.sock;
}
}
And then did a
$ ln -s /etc/nginx/sites-available/trumporate /etc/nginx/sites-enabled
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Now if I try to do GET request to the API endpoint from outside the ec2 box
$ curl -X GET http://public_ip/api/v1/trump/rant
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.0 (Ubuntu)</center>
</body>
</html>
Same case when I try to do it from inside the ec2 container too
$ curl -X GET http://localhost:80/api/v1/trump/rant/
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.0 (Ubuntu)</center>
</body>
</html>
log files
# /var/log/nginx/access.log
dev_box_ip - - [03/May/2017:05:50:45 +0000] "GET /api/v1/trump/rant/ HTTP/1.1" 404 580 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"
127.0.0.1 - - [03/May/2017:06:13:26 +0000] "GET /api/v1/trump/rant/ HTTP/1.1" 404 178 "-" "curl/7.47.0"
dev_box_ip - - [03/May/2017:07:42:42 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36"
/var/log/nginx$ cat error.log
/var/log/nginx$
/var/log/trumporate$ cat gunicorn-access.log
/var/log/trumporate$
$ cat gunicorn-error.log
[2017-05-03 06:28:41 +0000] [1884] [INFO] Starting gunicorn 19.7.1
[2017-05-03 06:28:41 +0000] [1884] [INFO] Listening at: unix:trumporate.sock (1884)
[2017-05-03 06:28:41 +0000] [1884] [INFO] Using worker: sync
[2017-05-03 06:28:41 +0000] [1889] [INFO] Booting worker with pid: 1889
[2017-05-03 06:28:41 +0000] [1890] [INFO] Booting worker with pid: 1890
[2017-05-03 06:28:41 +0000] [1891] [INFO] Booting worker with pid: 1891
[2017-05-03 06:29:48 +0000] [1884] [INFO] Handling signal: term
[2017-05-03 06:29:48 +0000] [1889] [INFO] Worker exiting (pid: 1889)
[2017-05-03 06:29:48 +0000] [1890] [INFO] Worker exiting (pid: 1890)
[2017-05-03 06:29:48 +0000] [1891] [INFO] Worker exiting (pid: 1891)
[2017-05-03 06:29:49 +0000] [1884] [INFO] Shutting down: Master
[2017-05-03 06:30:27 +0000] [1122] [INFO] Starting gunicorn 19.7.1
[2017-05-03 06:30:27 +0000] [1122] [INFO] Listening at: unix:trumporate.sock (1122)
[2017-05-03 06:30:27 +0000] [1122] [INFO] Using worker: sync
[2017-05-03 06:30:27 +0000] [1264] [INFO] Booting worker with pid: 1264
[2017-05-03 06:30:27 +0000] [1266] [INFO] Booting worker with pid: 1266
[2017-05-03 06:30:28 +0000] [1267] [INFO] Booting worker with pid: 1267
/var/log/trumporate$
EDIT
Relevant part of the flask app
#app.route('/api/v1/trump/rant/')
def return_rant():
foo = # logic
return jsonify(rant=foo)
Did you do nginx -s reload && systemctl restart nginx?
Another thing which you could try is to make the bindings on a http port instead of a socket:
--bind 127.0.0.1:6767 #in systemd config
and change nginx config as follows:
location / {
include proxy_params;
proxy_redirect off;
proxy_pass http://127.0.0.1:6767;
}
Also why do you have private_ip in nginx config?
server_name private_ip_address;
Change that to
server_name "_";
# OR
server_name PUBLIC_IP;
and remove all default configs from /etc/nginx/site-enabled
1) use of server_name private_ip_address;?
Nginx uses the server_name to check with the host header of the incoming request, and that isn't the private address. (You usually access using either a domain name or the public address in the URL bar)
2) I deleted /etc/nginx/site-enabled/default dir to make things to get to working.
If your server_name is not set correctly, nginx processes the request using the default file or the server block containing default_server. Thus I asked you to delete that file just in case there was an issue with your server name ^_^
Also, what difference would it make to the performance of the API if I am binding it to a port instead of the socket file as suggested by the blog post?
This would typically be premature optimization, any difference you get will purely be within a margin of error compared to the bottlenecks caused by flask/python and especially database connections. Though please take this with a grain of salt as I do not have any reliable source to quote this on.