nginx 에서 IP주소로 접속시 return

nginx 에서 IP주소로 접속시 return

QA

nginx 에서 IP주소로 접속시 return

본문

안녕하세요!!


http://xxx.xxx.xxx.xxx  ip주소로 접속시 아래처럼 하면 404 에러페이지를 보여줍니다.

server {
        listen 80 default;
        listen [::]:80 default;

        return 404;
}
 

그런데, 위와 같이 하면 http에서만 작동되더군요.

 

https://xxx.xxx.xxx.xxx 처럼 https 아이피주소로 접속시에도 404로 처리하려면 어떻게 해야 하나요?

미리 감사드립니다.

이 질문에 댓글 쓰기 :

답변 2


server {
        listen 443 default;
        listen [::]:443 default;
        return 404;
}

답변감사합니다.

위 내용은 추가 하고 nginx 재식작 하면 아래와 같은 메세지가 나옵니다.

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


"journalctl -xe" 로 화인해보면 아주~~~~~~~~~~~~~~긴 내용이 나오는데 무슨 내용인지 모르겠습니다. ㅎ...  마지막 몇줄만 올려볼게요.


-- The unit nginx.service has successfully entered the 'dead' state.
Feb 20 20:26:31 carway systemd[1]: Stopped A high performance web server and a reverse proxy server.
-- Subject: A stop job for unit nginx.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit nginx.service has finished.
--
-- The job identifier is 488999 and the job result is done.
Feb 20 20:26:31 carway systemd[1]: Starting A high performance web server and a reverse proxy server...
-- Subject: A start job for unit nginx.service has begun execution
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit nginx.service has begun execution.
--
-- The job identifier is 488999.
Feb 20 20:26:31 carway nginx[832423]: nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /et>
Feb 20 20:26:31 carway nginx[832423]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 20 20:26:31 carway systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStartPre= process belonging to unit nginx.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Feb 20 20:26:31 carway systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Feb 20 20:26:31 carway systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit nginx.service has finished with a failure.

ssl 적용되었으면 아래처럼 해 보세요.


server {
         listen 443 ssl;
         server_name _;
         ssl_certificate /etc/nginx/ssl/nginx.crt; //자신의 경로로 수정 하셔야 합니다.
         ssl_certificate_key /etc/nginx/ssl/nginx.key; //자신의 경로로 수정 하셔야 합니다.
         return       404;
}

보니까..

이렇게 포트가 2개로 이루어진거 아녀요? 여기서 접속할때 http 에 따로 리다이렉트 하고

https도 마찬가지로 리다이렉트해서 하는건 아닌가요?

 

server {
        listen 80;
        server_name domain.com;

}

 

server {
        listen 443;
        server_name domain.com;

}

답변 갑사합니다.

도메인 말고, 서버 아이피주소로 접속시 강제로 404 페이지를 보여주고 싶어요~

도메인은 현재 정상적으로 접속됩니다. ( http로 접속시 https로 연결 )

알려주신 내용대로 코드 작성하면 아래와 같이 오류입니다. ㅠㅠ

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

현재 Let's Encrypt 적용해서 정상적으로 사용하고 있습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 20
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT