server {
# listen on port 80 (http)
listen 80;
server_name _;
location / {
# redirect any requests to the same URL but on https
return 301 https://$host$request_uri;
}
}
server {
# listen on port 443 (https)
listen 443 ssl;
server_name _;
# location of the self-signed SSL certificate
ssl_certificate /home/certs/cert.pem;
ssl_certificate_key /home/certs/key.pem;
# write access and error logs to /var/log
access_log /var/log/server.log;
error_log /var/log/server.log;
location / {
# forward application requests to the gunicorn server
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 {
# handle static files directly, without forwarding to the application
alias /home/server/app/static;
expires 30d;
}
}
[Unit]
Description=Start-n
After=default.target
[Service]
WorkingDirectory=/home/server/app/
ExecStart=/home/server/app/.venv/bin/gunicorn -w 1 -b 0.0.0.0:8000 run:app
[Install]
WantedBy=default.target
class User(UserMixin, db.Model):
__table_name__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
login: Mapped[str] = mapped_column(String(64), index=True, unique=True)
password_hash: Mapped[Optional[str]] = mapped_column(String(256))
name: Mapped[Optional[str]] = mapped_column(String(64))
aboutme: Mapped[Optional[str]] = mapped_column(String(256))
contact_info: Mapped[Optional[str]] = mapped_column(String(256))
account_type: Mapped[str] = mapped_column(String(256), default='student')
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
def __repr__(self):
return '<User {} : {} : {}>'.format(self.login, self.name, self.id)
@login.user_loader
def load_user(id):
return db.session.get(User, int(id))
app.app_context().push()
в файле app.py│ app.py
│ config.py
│ forms.py
│ models.py
│ routes.py
│ run.py
├───static
│ └ some files...
├───templates
│ └ some files...