공부

nginx 설정

코딩이좋아요 2023. 7. 27. 16:30

네이버클라우드플랫폼 

프론트 - 오브젝트 스토리지

서버 - 서버

ssl - let's encript

도메인 - 가비아

recode - 글로벌DNS

 

네이버클라우드플랫폼은 지정 도메인 연결은 지원하지 않는다.

모든 처리를 서버에서 진행

프론트에서 정적 웹 사이트 호스팅 앤드포인트를 서버의 / 경로에서 처리를 한다. 

----

루트 경로 말고 다른 경로에서 처리하지 않는 이유는 /image 로케이션으로 처리할 시 

http://domain.com.s3-website.kr.object.ncloudstorage.com/image 로 처리하기 때문에 오브젝트 스토리지 버킷의 경로로 이동을 해버려서 오류가 난다. 그래서 루트 경로로 처리한다.

 인증서는  Let's Encrypt로 처리한다.

아래의 nginx설정으로 따른다면 정상적으로 작동한다.

server {
	#http 요청
        listen 80;
        server_name domain.com;
 location / {
        proxy_pass http://domain.com.s3-website.kr.object.ncloudstorage.com;
        proxy_read_timeout 600;
    }
 location /domain {
          proxy_pass http://127.0.0.1:3332/api/v1;
          proxy_read_timeout 600;

        }
# 	http로 오는 요청을 무조건 https로 보낼때
#       return 301 https://domain.com$request_uri; 
        #listen [::]:80;
}
server {
        # SSL configuration
        #https 요청
        listen 443 ssl;
        server_name domain.com;
        ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

     #server_name domain.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
       proxy_pass http://domain.com.s3-website.kr.object.ncloudstorage.com;
        proxy_read_timeout 600;
        }
        location /domain {
          proxy_pass http://127.0.0.1:3332/api/v1;
          proxy_read_timeout 600;

        }
}

 

http, https 혼합 콘텐츠 설정(비디오)

기본적으로 https를 사용하기 때문에 http요청을 자동으로 막아버리기 때문에 사용할 수 없어서

오브젝트 스토리지를 새로 하나 파서 웹 사이트 호스팅에 - 리다이렉션 선택 - 도메인 입력후 (example.com) 프로토콜을 http로 선택한다.
그 후 프론트에서 버튼을 눌렀을 때 새로 생성한 오브젝트 스토리지 앤드포인트로 새창 열기(or 팝업)  비디오 플레이어를 작동 시킨다.

그렇게 되면 정상적으로 http 영상들을 사용 가능하다.