- 프로젝트 소개: 나만의 Portfolio 사이트 만들기
- 개발기간: 2024.07.01~2024.07.11
- 기술스택
Environment
Development
Deployment
- git push
- git pull
- sudo systemctl restart portfolio.service
- sudo systemctl restart nginx
- Install git
sudo apt-get install git
- Install curl
sudo apt-get install curl
- Install pyenv
curl https://pyenv.run | bash
- Install packages
sudo apt-get update;
sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget llvm liblzma-dev \
libncurses-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev \
libffi-dev python3-tk
- Change Time zone
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
- PATH 등록(~/.bashrc 또는 ~/.bash_profile에 등록)
# pyenv path add
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# pyenv-virtualenv add
eval "$(pyenv virtualenv-init -)"
- python 설치 및 가상환경 생성
# Install python on pyenv
pyenv install 3.12.4
# Create virtual env
pyenv virtualenv 3.12.4 venv_portfolio
- git clone
git clone https://github.com/Jeong-Beom/Portfolio.git
- 가상환경 진입 후 requirements.txt 내용으로 필요 패키지 설치
# 개발서버에서 진입시 사용
cd Portfolio
. enter_local.sh
# 운영서버에서 진입시 사용
cd Portfolio
. enter_prod.sh
pip install wheel # 해당 패키지는 운영 서버에서만 설치
pip install -r requirements.txt
- Create .env file(+ migrate)
sudo nano .env
# 개발환경
SECRET_KEY={Django Secret Key}
DEBUG=True
# 운영환경
SECRET_KEY={Django Secret Key}
IP={IP 주소}
DEBUG=False
DOMAIN={Domain 주소}
DJANGO_SETTINGS_MODULE=config.settings.prod
# Django 운영시 필요한 파일들 생성(.gitignore에 위치하여 없는 파일들 대상)
python manage.py migrate
- Install gunicorn(WSGI), nginx(Web Server)
pip install gunicorn
sudo apt install nginx
- Move to '/etc/systemd/system/' and create service file.
- check user, group info
id
- create service file
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=imadmin
Group=imadmin
WorkingDirectory=/home/imadmin/Portfolio
EnvironmentFile=/home/imadmin/Portfolio/.env
ExecStart=/home/imadmin/.pyenv/versions/venv_portfolio/bin/gunicorn \
--workers 2 \
--bind unix:/tmp/gunicorn.sock \
config.wsgi:application
[Install]
WantedBy=multi-user.target
- execute portfolio.service and check error.
sudo systemctl daemon-reload
sudo systemctl start portfolio.service
sudo systemctl status portfolio.service
sudo systemctl enable portfolio.service
- Move to '/etc/nginx/sites-available/' and create file for nginx.
- create portfolio file
sudo nano portfolio
# portfolio - if it doesn't exist domain. it is needed to open 80 port. it is needed to change as environment.
server {
listen 80;
server_name {IP 주소};
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
alias /home/imadmin/Portfolio/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/tmp/gunicorn.sock;
}
}
# portfolio - if it exists domain. it is needed to open 80, 443 port. it is needed to change as environment.
server {
listen 80;
server_name {도메인 명칭};
rewrite ^https://$server_name$request_uri? permanent;
}
server {
listen 443 ssl;
server_name {도메인 명칭};
ssl_certificate /etc/letsencrypt/live/{도메인 명칭}/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/{도메인 명칭}/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
alias /home/imadmin/Portfolio/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/tmp/gunicorn.sock;
}
}
- move to '/etc/nginx/sites-enabled/' and delete default. create portfolio(link)
sudo rm default
sudo ln -s /etc/nginx/sites-available/portfolio
- check error and restart nginx
sudo nginx -t
sudo systemctl restart nginx
- Move to project directory(~/Portfolio/) and execute commands.
python manage.py collectstatic
sudo systemctl restart portfolio.service