Skip to content

Commit 0728353

Browse files
committed
The config files for the server.
1 parent 79fd48d commit 0728353

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
server {
2+
listen 80;
3+
server_name fake_pypi.com;
4+
server_tokens off;
5+
charset utf-8;
6+
client_max_body_size 150M;
7+
8+
___location /static {
9+
gzip on;
10+
gzip_buffers 8 256k;
11+
uwsgi_buffers 8 256k;
12+
13+
alias /apps/app_repo/app/ch15_deploy/final/pypi_org/static;
14+
expires 365d;
15+
}
16+
___location / {
17+
try_files $uri @yourapplication;
18+
}
19+
___location @yourapplication {
20+
include uwsgi_params;
21+
22+
gzip on;
23+
gzip_buffers 8 256k;
24+
uwsgi_buffers 8 256k;
25+
uwsgi_read_timeout 300;
26+
27+
proxy_pass http://127.0.0.1:5000;
28+
proxy_set_header Host $host;
29+
proxy_set_header X-Real-IP $remote_addr;
30+
proxy_set_header X-Forwarded-Protocol $scheme;
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=uWSGI PyPI server instance
3+
After=syslog.target
4+
5+
[Service]
6+
ExecStart=/apps/venv/bin/uwsgi -H /apps/venv --master --processes 4 --threads 2 --http :5000 --manage-script-name --python-path /apps/app_repo/app/ch15_deploy/final --mount /=wsgi:app
7+
RuntimeDirectory=/apps/app_repo/app/ch15_deploy/final/
8+
Restart=always
9+
KillSignal=SIGQUIT
10+
Type=notify
11+
StandardError=syslog
12+
NotifyAccess=all
13+
14+
[Install]
15+
WantedBy=multi-user.target
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
# Consider running these two commands separately
4+
# Do a reboot before continuing.
5+
apt update
6+
apt upgrade -y
7+
8+
apt install zsh
9+
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
10+
11+
# Install some OS dependencies:
12+
sudo apt-get install -y -q build-essential git unzip zip nload tree
13+
sudo apt-get install -y -q python3-pip python3-dev python3-venv
14+
sudo apt-get install -y -q nginx
15+
# for gzip support in uwsgi
16+
sudo apt-get install --no-install-recommends -y -q libpcre3-dev libz-dev
17+
18+
# Stop the hackers
19+
sudo apt install fail2ban -y
20+
21+
ufw allow 22
22+
ufw allow 80
23+
ufw allow 443
24+
ufw enable
25+
26+
# Basic git setup
27+
git config --global credential.helper cache
28+
git config --global credential.helper 'cache --timeout=720000'
29+
30+
# Be sure to put your info here:
31+
git config --global user.email "[email protected]"
32+
git config --global user.name "Your name"
33+
34+
# Web app file structure
35+
mkdir /apps
36+
chmod 777 /apps
37+
mkdir /apps/logs
38+
mkdir /apps/logs/pypi
39+
mkdir /apps/logs/pypi/app_log
40+
cd /apps
41+
42+
# Create a virtual env for the app.
43+
cd /apps
44+
python3 -m venv venv
45+
source /apps/venv/bin/activate
46+
pip install --upgrade pip setuptools
47+
pip install --upgrade httpie glances
48+
pip install --upgrade uwsgi
49+
50+
51+
# clone the repo:
52+
cd /apps
53+
git clone https://github.com/talkpython/data-driven-web-apps-with-flask app_repo
54+
55+
# Setup the web app:
56+
cd cd /apps/app_repo/app/ch15_deploy/final/
57+
pip install -r requirements.txt
58+
59+
# Copy and enable the daemon
60+
cp /apps/app_repo/app/ch15_deploy/final/server/pypi.service /etc/systemd/system/pypi.service
61+
62+
systemctl start pypi
63+
systemctl status pypi
64+
systemctl enable pypi
65+
66+
# Setup the public facing server (NGINX)
67+
apt install nginx
68+
69+
# CAREFUL HERE. If you are using default, maybe skip this
70+
rm /etc/nginx/sites-enabled/default
71+
72+
cp /apps/app_repo/app/ch15_deploy/final/server/pypi.nginx /etc/nginx/sites-enabled/pypi.nginx
73+
update-rc.d nginx enable
74+
service nginx restart

0 commit comments

Comments
 (0)