IT/서버

nginx에서 flask 앱 돌리기 위한 설정

thesse 2021. 6. 8. 09:29
300x250
반응형

nginx 설치

sudo apt install nginx

 

설정파일 (sites-available)

ubuntu@ip...:~$ cd /etc/nginx/sites-available/
ubuntu@ip...:/etc/nginx/sites-available$ sudo vi myproject

myproject

server {
  listen 80;
  server_name 3.35.xxx.xx;

  location = /favicon.ico { access_log off; log_not_found off; }
  location /static {
  	alias /home/ubuntu/projects/myproject/pybo/static;
  }
  location / {
    include proxy_params;
    proxy_pass http://unix:/tmp/myproject.sock;
  }
}

 

설정파일 적용 (sites-enabled)

#이동
ubuntu@ip...:/etc/nginx/sites-available$ cd ../
ubuntu@ip...:/etc/nginx$ cd sites-enabled/

#기존 적용된 default 링크 삭제
ubuntu@ip...:/etc/nginx/sites-enabled$ ll
total 8
drwxr-xr-x 2 root root 4096 Jun  7 16:57 ./
drwxr-xr-x 8 root root 4096 Jun  7 16:57 ../
lrwxrwxrwx 1 root root   34 Jun  7 16:57 default -> /etc/nginx/sites-available/default

#myproject 링크 생성
ubuntu@ip...:/etc/nginx/sites-enabled$ sudo rm default
ubuntu@ip...:/etc/nginx/sites-enabled$ sudo ln -s /etc/nginx/sites-available/myproject
ubuntu@ip...:/etc/nginx/sites-enabled$ ls
myproject

 

nginx 재시작

ubuntu@ip...:/etc/nginx/sites-enabled$ sudo systemctl restart nginx

 

정상 작동여부 확인

ubuntu@ip...:/etc/nginx/sites-enabled$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

 

브라우저에서 접속시 잘 돌아가는거 확인

300x250
반응형