-
Buat file wsgi.py di folder project root flask dengan is file dengan code berikut:
from myproject import app if __name__ == "__main__": app.run()
-
Buat file config ini uwsg contoh dengan nama file project-flask.ini di dalam folder project root flask dengan isi file berikut
[uwsgi] module = wsgi:app master = true processes = 5 socket = project-running.sock chmod-socket = 660 vacuum = true die-on-term = true
-
Buat file service untuk start/stop flask di contoh dengan nama file project-flask.service di dalam folder /etc/systemd/system/ Contoh:
sudo vi /etc/systemd/system/project-flask.serviceDengan isi file
[Unit] Description=uWSGI Server flask After=network.target [Service] User=apache Group=apache WorkingDirectory=/home/sysop/project-flask Environment="PATH=/home/sysop/virtualenv/bin" ExecStart=/home/sysop/virtualenv/bin/uwsgi --ini project-flask.ini [Install] WantedBy=multi-user.target
-
Selanjutnya start service uWsgi
Untuk start service atau menjalankan service
sudo systemctl start project-flaskUntuk mendaftarkan service supaya setiap kali server di restart service auto run
sudo systemctl enable project-flaskUntuk melihat service sudah running atau tidak
sudo systemctl status project-flaskNOTE: Nama project-flask adalah nama dari nama file project-flask.service yang sudah di buat sebelumnya
-
Buat proxy uwsgi ke web server nginx
sudo vi /etc/nginx/conf.d/project-flask.confDengan isi fileserver { listen 80; server_name ALAMAT_IP; location / { include uwsgi_params; uwsgi_pass unix:/home/sysop/project-flask/project-running.sock; } }
NOTE: ALAMAT_IP di ganti dengan alamat IP SERVER atau DOMAIN SERVER
-
Restart web server nginx
sudo systemctl status nginxNote: Jika tidak ada error, silahkan buka aplikasi di web
Last active
March 30, 2020 03:56
-
-
Save nim4n136/68a536b1c88aee3d66c92342a3b1c631 to your computer and use it in GitHub Desktop.
Cara deploy flask dengan uwsgi centos
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment