본문 바로가기

ETC

nginx / nginx 환경설정 및 도메인(domain) 변경 방법

 

도메인 설정을 변경하는 방법을 xshell에서 했던 걸 기록.

laravel로 만든 홈페이지를 django로 conversion하면서 도메인을 옮기게되어 이를 수정했다.

 

 

 

*사용할 폴더

cd /etc/nginx/

 

** nginx.conf 파일에서 include 해서 conf.d 와 sites-enabled를 사용함

 

 

 

1.  conf.d 폴더로 이동

cd /etc/nginx/conf.d/  (라라벨 conf 파일 있는 폴더)

 

2. 수정할 conf 파일로 들어가기

vi [파일명.conf]

바꾸려는 희망하는 url을 제외한 나머지만 server_name에 두기 

 

3. url 추가할 conf 파일로 이동 

cd /etc/nginx/sites-available/ (python conf 파일 있는 폴더)
vi [파일명]

 

4. port 변경 및 server_name 변경

4-1 http port 추가

4-2 https port 추가

 

 

 

 

 

 

 

 

 

 

 

 

 

 

* 위에 server는 http용 /

아래 server는 https용

 

 

 

① http로 접속시 https로 이동하도록 return 해준다. 

② listen에 443 ssl 작성

③ ssl 인증서, 인증키 작성

④ https로 클라이언트가 url 입력시 root 디렉토리 설정

 

 

💡 기본 포트 💡

http 기본포트 80
https 기본포트 443

ex.

 

(출처 | https://johngrib.github.io/wiki/why-http-80-https-443/)

 

 

5. 명령어 입력 후 실행

nginx -t # nginx 테스트로 돌려봄(이상 없는지)
systemctl restart nginx # nginx 재시작
systemctl daemon reload # daemon 리로드
sudo systemctl restart gunicorn2 # 장고사용을 위해서
sudo systemctl status gunicorn2 : 상태확인. Active 나오면 ok.

 

 

*** nginx restart 시 아래와 같은 error가 뜬다면, 변경한 conf 파일 재 확인. 오타일 가능성이 높음.

Restart가 안된다는 뜻.

 

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

 

 

 

 

아직 서버는 너무 어렵다..

nginx 는 더 공부해야지

 

nginx 공부는 여기가 좋은듯!

https://whatisthenext.tistory.com/123

반응형