최근 SSL 인증서가 만료되었습니다. 인증서를 갱신하기 위해 certbot을 사용했지만 이제 호스팅에서 인증서가 자동으로 갱신됩니다. 하지만 그 전에 서버에서 http에서 https로 리디렉션을 수행해야 합니다. 도와주실 수 있나요?
systemctl 상태 nginx.service:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
Active: failed (Result: exit-code) since Sun 2019-08-18 07:42:13 CEST; 2 days
Docs: man:nginx(8)
Process: 11855 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5
Process: 11590 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s
Process: 27222 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (cod
Process: 27214 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
Main PID: 11583 (code=exited, status=0/SUCCESS)
Aug 18 07:42:11 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:443 fai
Aug 18 07:42:11 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:80 fail
Aug 18 07:42:12 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:443 fai
Aug 18 07:42:12 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:80 fail
Aug 18 07:42:12 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:443 fai
Aug 18 07:42:12 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:80 fail
Aug 18 07:42:13 vps685363 nginx[27222]: nginx: [emerg] still could not bind()
Aug 18 07:42:13 vps685363 systemd[1]: nginx.service: Control process exited, cod
Aug 18 07:42:13 vps685363 systemd[1]: nginx.service: Failed with result 'exit-co
Aug 18 07:42:13 vps685363 systemd[1]: Failed to start A high performance web ser
nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
기본:
server {
server_name domukasi.pl www.domukasi.pl;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domukasi.pl/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domukasi.pl/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}server {
if ($host = www.domukasi.pl) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = domukasi.pl) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name domukasi.pl www.domukasi.pl;
listen 80;
return 404; # managed by Certbot
}
이 오류는 내 웹사이트(domukasi.pl)에서 발생합니다.
ERR_TOO_MANY_REDIRECTS
또한 nginx 서버를 다시 시작할 수 없습니다.
답변1
-server가 시작되지 않았기 ERR_TOO_MANY_REDIRECTS
때문에 브라우저에서 오류가 발생하는 것이 이상합니다 .nginx
일부 다른 서버가 이미 포트 80 및 443을 수신하고 있는 것으로 보이며 이로 인해 리디렉션이 발생하고 nginx
시작이 실패하게 됩니다.
오류 로그에서
Aug 18 07:42:12 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:443 fai
Aug 18 07:42:12 vps685363 nginx[27222]: nginx: [emerg] bind() to 0.0.0.0:80 fail
이는 nginx
해당 포트에 바인딩할 수 없음을 나타냅니다. 이는 해당 포트가 이미 다른 프로세스에서 사용 중이거나 nginx
해당 포트에 바인딩할 수 있는 권한이 충분하지 않음을 나타냅니다(1024 미만이므로). 이 컴퓨터에서 해당 포트를 사용하는 다른 서버가 이미 실행되고 있는 것 같습니다.
발급을 통해 해당 포트가 이미 사용되고 있는지 확인할 수 있습니다.
sudo lsof -i :80
그리고
sudo lsof -i :443
또는
sudo netstat -ltnp | grep -w ':80'
그리고
sudo netstat -ltnp | grep -w ':443'
이 기본 파일을 사용해 보세요
##############################################
#
# HTTP (port 80) domukasi.pl
#
##############################################
server {
server_name domukasi.pl www.domukasi.pl;
listen 80;
# redirect EVERYTHING from HTTP to HTTPS
location / {
return 301 https://$host$request_uri;
}
}
##############################################
#
# HTTPS (port 443) domukasi.pl
#
##############################################
server {
server_name domukasi.pl www.domukasi.pl;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domukasi.pl/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domukasi.pl/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
#######################################
# location /websocket {
# # proxy_http_version 1.1;
# proxy_read_timeout 31536000;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
# proxy_pass http://127.0.0.1:3000/websocket;
# }
#######################################
location / {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Name $server_name;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Name $server_name;
proxy_set_header X-Forwarded-IP $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Remote-IP $remote_addr;
proxy_set_header X-Forwarded-Remote-Port $remote_port;
proxy_set_header X-Forwarded-Server-IP $server_addr;
proxy_set_header X-Forwarded-Server-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:3000/;
}
}