Programming/클라우드 컴퓨팅 & AWS

[AWS] nginx에서 CSS 적용하기 ( static 파일 )

MOONCO 2021. 4. 8. 11:30

 

 

[AWS] nginx란? / django 프로젝트 nginx 웹 서버 연결하기

requirements.txt # manage.py가 있는 폴더에서 실행해야 정확한 패키지 정보를 불러올 수 있습니다. github에 프로젝트 올리기 / defineall.tistor.." data-og-host="defineall.tistory.com" data-og-source-u....

defineall.tistory.com

이전 포스팅과 이어집니다.


STATIC 경로 설정 확인하기 ( 내 컴퓨터/프로젝트/settings.py )

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

 

nginx에게 STATIC 경로 알려주기 ( 내 컴퓨터/프로젝트/.config/nginx/프로젝트.conf )

server {
    listen 80;
    server_name <퍼블릭DNS>
    charset utf-8;
    client_max_body_size 128M;

    location / {
        uwsgi_pass unix://tmp/<프로젝트>.sock;
        include uwsgi_params;
    }

    location /static/ {
        alias /home/ubuntu/<프로젝트>/static/;
    }
}

 

수정사항 있으면 github에 올리고, AWS에서 내려받기 ( AWS/프로젝트 )

############## 내컴퓨터 ################

git add .

git commit -m "메모"

git push

################ AWS ###################

git pull origin <브랜치>

 

nginx에 적용하기 위해, AWS에서 static 파일 하나로 모으기  ( AWS/프로젝트 )

python3 manage.py collectstatic

 

수정한 nginx 설정파일 다시 적용해주기

sudo cp -f /home/ubuntu/<프로젝트>/.config/nginx/<프로젝트>.conf /etc/nginx/sites-available/<프로젝트>.conf

sudo ln -sf /etc/nginx/sites-available/<프로젝트>.conf /etc/nginx/sites-enabled/<프로젝트>.conf

 

nginx, uwsgi 재시작하기

sudo systemctl daemon-reload

sudo systemctl restart uwsgi nginx

 

AWS 서버 접속하기! ( 퍼블릭DNS )

css가 적용되었다!

 

 

 

반응형