You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/DigitalOcean Tutorial.md
+59-2Lines changed: 59 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -340,12 +340,20 @@ root /usr/share/nginx/html;
340
340
341
341
Basically, the above config allows nginx to send the request, coming from our user, to our app. It also sets up some error pages for our service using nginx predefined pages.
342
342
343
-
And at last, in order to enable our configuration, we need to do something like this:
343
+
And then, in order to enable our configuration, we need to do something like this:
Since nginx will look into the default configuration instead of ours unless we delete this file.
356
+
349
357
### Setting up our app folder
350
358
351
359
First, we create a folder for our app:
@@ -420,6 +428,8 @@ And we will set up uWSGI in next section and finish deploying our app.
420
428
421
429
We will be using uWSGI to run the app for us, in this way, we can run it in multiple threads within multiple processes. It also allow us to log more easily. More details on uWSGI can be found [here](https://uwsgi-docs.readthedocs.io/en/latest/).
422
430
431
+
### Defining a uWSGI service
432
+
423
433
First, we define a uWSGI service in the system by:
424
434
425
435
```
@@ -458,7 +468,13 @@ The `ExecStart` property informs uWSGI on how to run our app as well as log it.
458
468
459
469
At last, the `WantedBy` property in `Install` section allows the service to run as soon as the server boots up.
460
470
461
-
***important:*** Remember to change the username, password, database name and service name/folder accordingly in your own code.
471
+
***Important:*** remember to change the username, password, database name and service name/folder accordingly in your own code.
472
+
473
+
*Hint:* after editting the above file, press `ESC` to quit insert mode and use `:wq` to write and quit.
474
+
475
+
### Configuring uWSGI
476
+
477
+
Our next step is to configure uWSGI to run our app. To do so, we need to create a file named `uwsgi.ini` with the following content:
462
478
463
479
```
464
480
[uwsgi]
@@ -483,3 +499,44 @@ callable = app
483
499
484
500
logto = /var/www/html/items-rest/log/%n.log
485
501
```
502
+
503
+
Note that you should change the `base` folder accordingly in your own app. For the second entry, `run` is referred to the `run.py` in our sample app, which serves as the entry point of our app, so you may need to change it accordingly in your own project as well. We defined the socket.sock file here which is required in our previous [nginx section](DigitalOcean%20Tutorial.md#configure-nginx-for-our-app). Hopefully everything should link together and starting to make sense now. We asked for 8 processes with 8 threads each for no particular reason, you may adjust them according to your server capacity and data volume. The `harakiri` is a Japanese word for suicide, so in here it means for how long (in seconds) will the `emperor` kill the thread if it has failed. This is also an advantage we have with uWSGI, it allows our service to be resilient to minor failures. And it also specifies the log location.
504
+
505
+
And at last, after saving the above file, we use the command below to run the uWSGI service we defined earlier:
506
+
507
+
```
508
+
sudo systemctl start uwsgi_items_rest
509
+
```
510
+
511
+
And we should be able to check the uWSGI logs immediately to make sure it's running by using the command:
512
+
513
+
```
514
+
vi /log/uwsgi.log
515
+
```
516
+
517
+
### Running our app
518
+
519
+
Finally, we can launch our app! We can do so by starting the nginx and uWSGI services we defined.
520
+
521
+
```
522
+
sudo systemctl start nginx
523
+
sudo systemctl start uwsgi_items_rest
524
+
```
525
+
526
+
If any of these services is already running, you may use the below commands (taking nginx for example) to reload and restart it so that it has the latest changes:
527
+
528
+
```
529
+
sudo systemctl reload nginx
530
+
sudo systemctl restart nginx
531
+
```
532
+
533
+
## Deployment wrap-up
534
+
535
+
As the tutorial is very detailed, you may find it a bit hard to put the pieces together. Here's a quick wrap-up that may help you sort things up.
536
+
537
+
- We created a unix user and granted him some privilege.
538
+
- We set up PostgreSQL and configured our user to interact with it.
539
+
- We used uWSGI to run our app multi-processly and multi-threadly.
540
+
- We used nginx to direct requests to our uWSGI service.
0 commit comments