I had a setup that was working fine, using git to push local development changes to a repo on Digital Ocean, which then uses a post-receive hook to send the master branch to /var/www/MYAPPNAME/ . I'm also using gunicorn via supervisor to run the site along with nginx -- now that I've added a git develop branch which is sent to /var/www/dev.MYAPPNAME/ I seem to be having problems (maybe a coincidence, maybe a problem introduced when updating supervisor/nginx config).
If I make a minor update to the HTML in my Flask app template /app/templates/index.html or /base.html for the dev version of my app/site, I can't get the site to display the changes. The dev subdomain seems to be pointing to the production app rather than the separate dev branch and associated code folder. I can tell code changes are getting to the correct folder (/var/www/dev.MYAPPNAME) but when I run "sudo supervisorctl reload" like I do to get code changes in the production folder to refresh on the live production site, the updated text in my HTML is not displaying.
I tried:
- Manually deleting pycache files/folders on server
- Reloading supervisor with sudo supervisorctl reload
- Adding TEMPLATES_AUTO_RELOAD=True and DEBUG=True to my .env file to attempt to force Jinja to reload templates
- Restarting Nginx
- Rebooting the server
MYAPPNAME.py file (same for both dev and production versions of site):
from app import app
/app/init.py file (also same for both):
from flask import Flask
app = Flask(__name__)
from app import routes
/app/routes.py (same for both sites):
from flask import render_template
from app import app
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html', title='MYAPPNAME')
/app/static just contains bootstrap.css and bootstrap.js
/app/templates contains the base.html and index.html which extends base.html - changes to both of which were working fine before I introduced the second/dev site to the server but are now not being recognized on the develop branch dev site.
.env file (which I also copied to .flaskenv file):
FLASK_APP=MYAPPNAME.py
TEMPLATES_AUTO_RELOAD=True
DEBUG=True
Here's my /etc/supervisor/conf.d/dev.MYAPPNAME.conf (would not be shocked if there was something wrong here):
[program:dev.MYAPPNAME]
command=/var/www/dev.MYAPPNAME/venv/bin/gunicorn -b localhost:8001 -w 4 MYAPPNAME:app
directory=/var/www/dev.MYAPPNAME
user=MYUSERNAME
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
And my non-dev /etc/supervisor/conf.d/MYAPPNAME.conf :
[program:MYAPPNAME]
command=/var/www/MYAPPNAME/venv/bin/gunicorn -b localhost:8000 -w 4 MYAPPNAME:app
directory=/var/www/MYAPPNAME
user=MYUSERNAME
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
Nginx config for dev site: /etc/nginx/sites-available/dev.MYAPPNAME (would also not be shocked if something was wrong with these two files):
server {
listen 80;
server_name dev.MYAPPNAME;
root /var/www/dev.MYAPPNAME;
access_log /var/log/dev.MYAPPNAME_access.log;
error_log /var/log/dev.MYAPPNAME_error.log;
location / {
proxy_pass http://localhost:8001;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /var/www/dev.MYAPPNAME/app/static;
expires 30d;
}
}
Nginx config for non-dev site: /etc/nginx/sites-available/MYAPPNAME :
server {
listen 80;
server_name MYAPPNAME;
root /var/www/MYAPPNAME;
access_log /var/log/MYAPPNAME_access.log;
error_log /var/log/MYAPPNAME_error.log;
location / {
proxy_pass http://localhost:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /var/www/MYAPPNAME/app/static;
expires 30d;
}
}
I appreciate any direction that can be given, other things I can check, obvious mistakes, etc. Thanks!