My Flask app works perfectly fine when it is running on its own without a reverse proxy, but for production I would like to have an HTTPS reverse proxy as I plan on running this application on the open internet. I got the proxy working for everything but file uploading. When a file is uploaded, the following error occurs:
AttributeError: 'AnonymousUserMixin' object has no attribute 'x'
The actual flask-login user has attribute x defined, but for some reason when uploading a file the application doesn't see that the user uploading a file is indeed an authenticated user. Here is my NGINX reverse proxy config:
server {
server_name example.com; # this is set to the actual DNS name
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
server {
server_name example.com; # this is set to the actual DNS name
listen 443 ssl http2;
listen [::]:443 ssl http2;
# enable subfolder method reverse proxy confs
include /config/nginx/proxy-confs/*.subfolder.conf;
# all ssl related config moved to ssl.conf
include /config/nginx/ssl.conf;
location / {
client_max_body_size 20m;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_redirect off;
proxy_pass http://127.0.0.1:5000$request_uri;
}
}
The reverse proxy works perfectly fine otherwise, user logins work along with all the other functionality of the application.