테스트 사이트 - 개발 중인 베타 버전입니다

nginx 에서 IP주소로 접속시 return 채택완료

루미집사 4년 전 조회 4,494

안녕하세요!!


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개

채택된 답변
+20 포인트
4년 전

</p>

<p>server {

        listen 443 default;

        listen [::]:443 default;</p>

<p>        return 404;

}</p>

<p>

로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

루미집사
4년 전
답변감사합니다.

위 내용은 추가 하고 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.
亞波治
4년 전
ssl 적용되었으면 아래처럼 해 보세요.

[code]
server {
listen 443 ssl;
server_name _;
ssl_certificate /etc/nginx/ssl/nginx.crt; //자신의 경로로 수정 하셔야 합니다.
ssl_certificate_key /etc/nginx/ssl/nginx.key; //자신의 경로로 수정 하셔야 합니다.
return 404;
}
[/code]
루미집사
4년 전
감사합니다.
알려 주신 내용대로 적용하여 해결 되었습니다!~~

댓글을 작성하려면 로그인이 필요합니다.

보니까..

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

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

 

server {
        listen 80;
        server_name domain.com;

}

 

server {
        listen 443;
        server_name domain.com;

}

로그인 후 평가할 수 있습니다

답변에 대한 댓글 5개

루미집사
4년 전
답변 갑사합니다.

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

도메인은 현재 정상적으로 접속됩니다. ( http로 접속시 https로 연결 )
릴보이즈
4년 전
보안인증서로 등록됐나여?
릴보이즈
4년 전
아무리 해도 코드 하이라이트가 안넣어지네여 ㅋㅋㅋㅋㅋㅋ
암튼 밑에꺼 처럼 해보셨나여 ㅋㅋ
<code>
server { listen 443; server_name 아이피주소; return 404; }
</code>
루미집사
4년 전
알려주신 내용대로 코드 작성하면 아래와 같이 오류입니다. ㅠㅠ

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 적용해서 정상적으로 사용하고 있습니다.
릴보이즈
4년 전
journalctl -xe 내용이 뭔데요 명령어 입력하면..
(저도 테스트해보고픈데 보안인증서 등록된게 없다보니 ㅠㅠ)

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인