nginx , uwsgi 를 연동하고 배포후 (deploy) 나서 장고에러또 발생했다

일전에 장고에러에 대해  404 not found django Server Error (500)

포스팅 했는데 그걸 해결하고 나서



나의 상황은 이랬다

루트페이지나 static file 은 잘불러와졌고

중간에 로그인을 할때나 특정 데이터를 불러오는 페이지가 안된다는 거였는데


nginx , uwsgi 를 연동 후 착오가 있었던게

nginx 실행 후

uwsgi start 후 

ssh 콘솔을 종료했는데 안되는고 자꾸 특정페이지 호출이 안되는 에러를 뿜어냈다

알고보니 콘솔종료하면서 nginx 는 서비스 백단에 떠있는데 uwsgi 는 서비스가 안떠있고 콘솔 종료 되면서 같이 종료되서 일어나는 현상이었다


그래서 uwsgi도 서비스로 백단에 띄워주는 작업을 하였다 서비스화 해서 띄워주는 환경설정 파일을 만들어 주자

Init Service 등록

# /etc/init/[APP_NAME].conf
# simple uWSGI script
description "[APP_NAME] real instance"
start on runlevel [2345]

stop on runlevel [06]

respawn

exec uwsgi --ini /var/product/project_path/uwsgi.ini

다 됐으면 service [APP_NAME] start / service [APP_NAME] stop 으로 켜고 끌 수 있다.

로컬에서 잘되던게 aws에 배포후 특정 템플릿을 부르려고 하면 404 not found 나 django Server Error (500)가 발생하는 현상이 일어났다


한참을 헤매고나서


보니 템플릿 html파일 중 메소드 호출이 안되는거 같았다 로컬에서는 잘 되었으나 


문제가 된 부분은 페이스북과 트위터 공유부분이었는데

<a target='_blank' href="https://twitter.com/home?status={{obj.get_share_message|safe }}">
<i class="fa fa-twitter-square fa-3x" aria-hidden="true"></i>
</a>
<a target='_blank' href="https://www.facebook.com/sharer/sharer.php?u={{obj.get_share_link }}">
<i class="fa fa-facebook-square fa-3x" aria-hidden="true"></i>
</a>

여기에서{{obj.get_share_message|safe }} 와

{{obj.get_share_link }}것이 문제였다 원래 개발서버에서는 잘 호출되던 것이었으나.... ㅠ

시간도 없고 해서 삭제 후에는 모든것이 배포 후 실 서버에서 잘 작동한다

nginx 설정 문법 검사를 하려고 아래 구문을 실행하면

sudo nginx -t

sudo service nginx configtest


django nginx error 에러가 난다

 [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 64


보니까 서버네임이 길어서 그런거 같은데, 이걸 짧게 해주거나 

그 밑에 가보면 디폴드 설정파일이 있더라 그걸 수정해 주면되는데


sudo nano /etc/nginx/nginx.conf 편집기를 열고

http {


        ##

        # Basic Settings

        ##


        sendfile on;

        tcp_nopush on;

        tcp_nodelay on;

        keepalive_timeout 65;

        types_hash_max_size 2048;

        # server_tokens off;


        server_names_hash_bucket_size 128;

        # server_name_in_redirect off;


해쉬버킷사이즈를 증가시켜 주니까 에러가 없어졌다

+ Recent posts