I’m trying to set up my Flask python app on Caddy, with my own domain. I used to run the website on grandpa Apache2 until someone told me about Caddy. I had a letsencrypt certificate for apache, which I have since certbot delete'd.
I’ve been attempting to follow this guide, which uses cgi.
I run Caddy by using caddy -conf <Caddyfile_path> and the Caddy output looks good I think (swapped my actual domain with domain.com below):
2020/05/05 11:01:11 [INFO] [www.domain.com] Server responded with a certificate.
done.
Serving HTTPS on port 443
https://www.domain.com
Serving HTTP on port 80
http://www.domain.com
WARNING: File descriptor limit 1024 is too low for production servers. At least 8192 is recommended. Fix with `ulimit -n 8192`.
However, unfortunately:
This is me curling the website from another machine:
My python script is titled server.py and works perfectly fine on Flask. I’ve followed that guide I linked to at the top to the T. My server.cgi file looks exactly identical to the one provided in the guide, as well (where yourapplication in my case is server).
Thank you for the help.
curl -i https://domain.com
HTTP/2 308
content-type: text/html; charset=utf-8
location: https://domain.com/
server: Caddy
content-length: 251
date: Tue, 05 May 2020 11:54:05 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="https://domain.com/">https://domain.com/</a>. If not click the link.
Oh, okay I think I have a better sense of the problem.
I can actually access all of the other pages on my website (e.g. domain.com/join, domain.com/explore, etc.) – the only page giving me trouble seems to be the home page, whose location is /
Here are relevant portions of my main python file if this helps:
from flask import Flask
from flask import render_template
from flask import Response, request, jsonify
app = Flask(__name__)
@app.route('/')
def mission(name=None):
return render_template('mission.html')
if __name__ == '__main__':
#main(app)
app.run(debug = True)
I’m not sure why the main page gives the redirection error…
Yeah I think that’s probably the best move. I hadn’t much realized that the guide I was following was modeled on Caddy v1, and not v2.
If by any chance you have any helpful links/examples, do please send them – mostly I’ve found this, although I believe I’d tried and was still getting any issues: examples/flask at master · caddyserver/examples · GitHub
I set everything up (even as a systemd service yay) and things are looking good now, thank you again.
Follow up question, what would be best practice on how to start up the uwsgi every time? Should I just have the command in a bash script somewhere / running in its own screen? Is there any way to automate that, or even to have caddy run the command if it senses it’s being enabled?
I’m trying to run this in prod haha but hey as long as it works right^^
Thank you again for the help
Had not realized my problem was a version one in part.