Witaj
Strona główna
Logowanie
Rejestracja
Zawartość
Contents
Technologie - Technologies
OVH, CloudFlare
Skopiuj IPv6 - Copy IPv6
OVH rekord AAAA - OVH record AAAA
Rekord AAAA - Record AAAA
IPv6 w nowym rekordzie - IPv6 in new record
IPv6 w nowym rekordzie - IPv6 in new record
CloudFlare
Dodaj domenę - Add new domain
Darmowy plan - Free plan
Nowy rekord - New record
Nowy rekord - New record
Nameservers
HTTPS
OVH serwery DNS - OVH DNS servers
Instalacja Pythona i Nginx - Installing Python and Nginx
Nginx
Python, virtualenv
Repozytorium - Repository
Środowisko wirtualne - Virtualenv
Włącz środowisko wirtualne - Turn on the virtualenv
Baza danych, admin - Database, admin
Plik .env - .env file
Serwer nginx, własny błąd 404 - Nginx server, own 404 error
Nginx serwer - Nginx server
Błąd 404 - 404 error
Gunicorn
Plik konfiguracyjny - Configuration file
Uruchom Gunicorna - Run Gunicorn
Wyłączenie Gunicorna - Disabling Gunicorn
Przeładowanie Gunicorna - Reloading Gunicorn
1. Technologie
1. Technologies
Backend: Python 3.11.1 (3.10.2 na VPS - 3.10.2 on VPS), Django 4.1.7
Frontend: Bootstrap
Dostawca domeny (Domain provider): OVH
Tunelowanie z IPv6 (Tunneling from IPv6): CloudFlare
VPS: Mikrus2.1
Serwer WWW (Server WWW): Nginx, Gunicorn
2. Dodanie adresu IP do OVH i CloudFlare
2. Adding an IP address to OVH and CloudFlare
2.1. Zaloguj się na swój serwer i skopiuj widoczny w czerwonym prostokącie adres IPv6
2.1. Log in to your server and copy the IPv6 address shown in the red rectangle
2.2. Zaloguj się do swojego konta OVH i dodaj nowy rekord
2.2. Log in to your OVH account and add a new record
2.3. Dodaj rekord AAAA
2.3. Add AAAA record
2.4. Dodaj adress IPv6 w miejsce czarnego prostokąta
2.4. Add the IPv6 address in place of the black rectangle
2.5. Dodaj adress IPv6 w miejsce czarnego prostokąta
2.5. Add the IPv6 address in place of the black rectangle
2.6. Zaloguj się na swoje konto w CloudFlare i dodaj nową stronę
2.6. Log in to your CloudFlare account and add a new site
2.7. Podaj swoją domenę
2.7. Enter your domain
2.8. Wybierz darmowy plan
2.8. Choose a free plan
2.9. Dodaj nowy rekord
2.9. Add new record
2.10. Wybierz AAAA, wpisz @, wklej ten sam adres IPv6, zaznacz pomarańczową chmurkę
2.10. Select AAAA, type @, paste the same IPv6 address, select the orange cloud
2.11. Punkty 2-5 zrobimy za chwilę. Przejdźmy dalej
2.11. We will do points 2-5 in a moment. Let's move on
2.12. Zaznacz wszystko
2.12. Mark everything
2.13. Podmień DNS u dostawcy domeny na te, o które poprosił CloudFlare
2.13. Replace DNS at the domain provider with the one requested by CloudFlare
3. Instalacja enviroment, nginxa i potrzebnych bibliotek
3. Installation of enviroment, nginx and needed libraries
3.1. Zaloguj się na VPSa i wyszukaj czy dostępny jest nginx w wersji extras
3.1. Log on to the VPS and search to see if nginx extras is available
apt search nginx | grep nginx
nginx-extras/jammy-updates,now 1.18.0-6ubuntu14.4 amd64 [installed]
nginx web/proxy server (extended version)
apt install nginx-extras
systemctl start nginx
systemctl status nginx
netstat -plntu
3.2. Zainstaluj potrzebne bilbioteki
3.2. Install the necessary libraries
sudo apt -y install python3-pip python3-dev
sudo pip3 install virtualenv
3.3. Pobierz repozytorium
3.3. Download the repository
cd
mkdir pskrzynski
cd pskrzynski
git clone https://github.com/skrzypa/mysite
3.4. Wejdź w nowo utworzony folder, a następnie utwórz środowisko wirtualne
3.4. Enter the newly created folder, then create a virtual environment
ls
cd mysite
virtualenv 0_venv
3.5. Włącz środowisko wirtualne, a następnie pobierz potrzebne bibliotek
3.5. Turn on the virtual environment, and then download the necessary libraries
source 0_venv/bin/activate
pip install django==4.1.7 gunicorn==21.2.0 django-bootstrap-v5==1.0.11 requests==2.30.0 django-environ==0.11.2 Pillow==9.5.0
3.6. Utwórz bazę danych, pliki statyczne oraz admina
3.6. Create database, static and admin
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic
python manage.py createsuperuser
3.7. Utwórz plik .env o następującej treści
3.7. Create an .env file with the following content
vim .env
DEBUG=False
SECRET_KEY=’twoj klucz’
#ALLOWED_HOSTS=[]
#CSRF_TRUSTED_ORIGINS=[]
ALLOWED_HOSTS=['127.0.0.1', 'pskrzynski.pl']
CSRF_TRUSTED_ORIGINS=['http://0.0.0.0:8000', 'https://pskrzynski.pl', 'https://*.pskrzynski.pl']
CSRF_COOKIE_SECURE=True
SESSION_COOKIE_SECURE=True
4. Serwer nginx, własny błąd 404
4. Nginx server, own 404 error
4.1. Wejdz w następujący plik, a następnie na samym początku wpisz poniższą treść
4.1. Go to the following file, and then at the very beginning, type the following content
vim /etc/nginx/sites-enabled/default
serwer {
listen 80;
listen [::]:80;
server_name pskrzynki.pl www.pskrzynski.pl;
set $expire_cache 3h;
expires $expire_cache;
error_page 404 /error404.html;
location = /error404.html {
root /var/www/my_erros;
}
location / {
proxy_pass http://127.0.0.1:8000;
}
location /podstrona_1/ {
proxy_pass http://127.0.0.1:8000;
}
location /podstrona_2/ {
proxy_pass http://127.0.0.1:8000;
}
...
}
nginx -t
nginx -s reload
4.2. Stwórz własny błąd 404
4.2. Create your own 404 error
cd /var/www/
mkdir my_errors
vim error404.html
Błąd 404
404 error
5. Gunicorn
5. Gunicorn
5.1. Stwórz plik konfiguracyjny
5.1. Create a configuration file
cd
cd pskrzynski
mkdir gunicorn_file
cd gunicorn_file
vim gconf.py
command = '/root/pskrzynski/mysite/0_venv/bin/gunicorn'
pythonpath = '/root/pskrzynski/mysite'
bind = '127.0.0.1:8000'
workers = 3
5.2. Uruchom Gunicorna, jeśli zobaczysz poniższą treść po wspisaniu tej komendy, twoja strona powinna być widoczna dla każdego pod twoją domeną
5.2. Run Gunicorn, if you see the following after typing this command, your site should be visible to everyone under your domain
cd
gunicorn -c pskrzynski/gunicorn_file/gconf.py mysite.wsgi
[2023-12-23 18:23:31 +0000] [38868] [INFO] Starting gunicorn 21.2.0
[2023-12-23 18:23:31 +0000] [38868] [INFO] Listening at: http://127.0.0.1:8000 (38868)
[2023-12-23 18:23:31 +0000] [38868] [INFO] Using worker: sync
[2023-12-23 18:23:31 +0000] [38869] [INFO] Booting worker with pid: 38869
[2023-12-23 18:23:31 +0000] [38870] [INFO] Booting worker with pid: 38870
[2023-12-23 18:23:32 +0000] [38871] [INFO] Booting worker with pid: 38871
5.3. Wyłączanie procesu odpowiedzialnego za Gunicorna
5.3. Disabling the process responsible for Gunicorn
ps -aux | grep gunicorn
root >PID< 0.0 1.8 33304 19096 ? ...
root >PID< 0.0 3.4 51984 36532 ? ...
root >PID< 0.0 4.0 57684 42252 ? ...
root >PID< 0.0 3.4 51904 36528 ? ...
root >PID< 0.0 0.2 9144 2296 pts/5 ...
kill -9 >PID<
5.4. Przeładowanie procesu odpowiedzialnego za Gunicorna
5.4. Reloading the process responsible for Gunicorn
kill -HUP >PID<
Patryk Skrzyński