Skip to content

Commit 54659ea

Browse files
committed
doc: nginx basic defintion + certbot SSL
1 parent ffa3d61 commit 54659ea

File tree

1 file changed

+131
-4
lines changed

1 file changed

+131
-4
lines changed

README.md

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ to run the server.
4343
Deploying a website involves :
4444

4545
- cloning the repository and setting up the virtual environment,
46+
- wrapping the start/stop of the taipy server with a systemd service
4647
- configuring nginx with a base setup listening on port 80 and then adding https
4748
support with a SSL certificate
48-
- wrapping the start/stop of the taipy server with a systemd service
4949

5050
### Cloning and virtual environment
5151

@@ -79,11 +79,138 @@ source .venv/bin/activate
7979
pip install uwsgi gevent
8080
```
8181

82+
### Systemd service file for running taipy
83+
84+
85+
8286
### Nginx setup
8387

84-
TBD
88+
#### Basic configuration with http support
89+
90+
For nginx, you can remove the default website :
91+
92+
```
93+
cd /etc/nginx/sites-enabled
94+
sudo rm -rf default
95+
```
96+
97+
Then add your website definition. The basic definition is almost the same
98+
whether you deploy the production or development website. In the template file
99+
below, you must replace the two variables `MY_SERVER_NAME` and `MY_PORT` as :
100+
101+
- `MY_SERVER_NAME` with `www.taxplorer.eu` and `MY_PORT` with `5000` for the
102+
production website,
103+
- `MY_SERVER_NAME` with `dev.taxplorer.eu` and `MY_PORT` with `5001` for the
104+
development website,
105+
106+
If you want to define both the production and development website, you can just
107+
consecutively define both.
108+
109+
**File /etc/nginx/sites-enabled/d4g-dataviz** :
110+
```
111+
server {
112+
listen 80;
113+
server_name MY_SERVER_NAME;
114+
add_header 'X-Frame-Options' 'SAMEORIGIN';
115+
add_header 'X-XSS-Protection' '1; mode=block';
116+
add_header 'X-Content-Type-Options' 'nosniff';
117+
add_header 'Referrer-Policy' 'same-origin';
118+
add_header 'Strict-Transport-Security' 'max-age=63072000';
119+
ssl_certificate /etc/letsencrypt/live/www.taxplorer.eu/fullchain.pem;
120+
ssl_certificate_key /etc/letsencrypt/live/www.taxplorer.eu/privkey.pem;
121+
location / {
122+
proxy_pass http://127.0.0.1:MY_PORT;
123+
#proxy_redirect off;
124+
#keepalive_requests 100;
125+
#proxy_read_timeout 75s;
126+
#proxy_connect_timeout 75s;
127+
#proxy_http_version 1.1;
128+
#client_max_body_size 100M;
129+
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
130+
#proxy_set_header X-Forwarded-Proto $scheme;
131+
#proxy_set_header X-Real-IP $remote_addr;
132+
proxy_set_header Host $http_host;
133+
proxy_set_header Upgrade $http_upgrade;
134+
proxy_set_header Connection 'upgrade';
135+
}
136+
}
137+
```
138+
139+
You can test the definition with :
140+
141+
```
142+
sudo nginx -t
143+
```
144+
145+
If there is no error, you can enable and start/restart the nginx service :
146+
147+
```
148+
sudo systemctl enable nginx
149+
sudo service nginx restart
150+
```
151+
152+
You should now be able to navigate to `www.taxplorer.eu`. If you do not have yet
153+
a binding between the domain name `www.taxplorer.eu` and the IP of the server
154+
hosting the website, you can anyway test the connection by getting the IP of
155+
the server with `ip addr` and then going to `http://IP_OF_THE_SERVER`.
156+
157+
### Adding the SSL support for https
158+
159+
For adding the SSL support for secured connection, we will use [certbot](https://certbot.eff.org/). For example, on a debian + nginx configuration, the steps to follow are :
160+
161+
```
162+
sudo apt update && sudo apt install -y snapd
163+
sudo snap install --classic certbot
164+
sudo ln -s /snap/bin/certbot /usr/bin/certbot
165+
sudo certbot --nginx
166+
```
167+
168+
From there, you will have to select the website for which you want to get and
169+
install a SSL certificate. Certbot will also modify your
170+
`/etc/nginx/sites-enabled/d4g-dataviz` file to 1) redirect any connection to
171+
port `80` to port `443` and adds the definition for using the certificate. For
172+
example, below is the definition for the development website :
173+
174+
```
175+
server {
176+
server_name dev.taxplorer.eu;
177+
178+
# SECURITY HEADERS
179+
add_header 'X-Frame-Options' 'SAMEORIGIN';
180+
add_header 'X-XSS-Protection' '1; mode=block';
181+
add_header 'X-Content-Type-Options' 'nosniff';
182+
add_header 'Referrer-Policy' 'same-origin';
183+
add_header 'Strict-Transport-Security' 'max-age=63072000';
184+
185+
location / {
186+
proxy_pass http://localhost:5001;
187+
proxy_set_header Upgrade $http_upgrade;
188+
proxy_set_header Connection 'upgrade';
189+
proxy_set_header Host $http_host;
190+
proxy_set_header X-Forwarded-Host $http_host;
191+
}
192+
193+
194+
listen 443 ssl; # managed by Certbot
195+
ssl_certificate /etc/letsencrypt/live/dev.taxplorer.eu/fullchain.pem; # managed by Certbot
196+
ssl_certificate_key /etc/letsencrypt/live/dev.taxplorer.eu/privkey.pem; # managed by Certbot
197+
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
198+
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
199+
200+
}
201+
202+
server {
203+
if ($host = dev.taxplorer.eu) {
204+
return 301 https://$host$request_uri;
205+
} # managed by Certbot
206+
207+
server_name dev.taxplorer.eu;
208+
listen 80;
209+
return 404; # managed by Certbot
210+
}
211+
212+
```
213+
85214

86-
### Systemd service file
87215

88-
TBD
89216

0 commit comments

Comments
 (0)