Мой адрес ratwires.space
. Конфигурация ниже правильно включает: https://ratwires.space
, https://www.ratwires.space
и http://www.ratwires.space
и перенаправляет http://www.ratwires.space
на https://www.ratwires.space
, однако не перенаправляет http://ratwires.space
на https://ratwires.space
.
Это для приложения Rails с Unicorn, работающим на порте 8080. Я добавил текущую поддержку HTTPS с помощью certbot, а затем настраивал ее, пока, по крайней мере, большинство доменов не заработало.
/etc/letsencrypt/live/ratwires.space-0002/
является сертификатом для *.ratwires.space
и ratwires.space
.
Приведенный ниже конфиг взломан из различных примеров, и я не знаю, что я здесь делаю.
worker_processes 1;
user root root;
pid /var/run/nginx.pid;
error_log /var/log/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /var/log/nginx.access.log combined;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/xml text/css
text/comma-separated-values
text/javascript application/x-javascript
application/atom+xml;
upstream app_server {
server unix:/root/Ratwires/shared/sockets/unicorn.sock fail_timeout=0;
}
server {
client_max_body_size 4G;
server_name *.ratwires.space;
keepalive_timeout 5;
root /root/Ratwires/public;
try_files $uri/index.html $uri.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:8080;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /root/Ratwires/public;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/ratwires.space-0002/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ratwires.space-0002/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = ratwires.space) {
return 301 http://$host$request_uri;
}
server_name *.ratwires.space;
return 404; # managed by Certbot
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/ratwires.space-0002/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ratwires.space-0002/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host ~ ^[^.]+\.ratwires\.space$) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default deferred;
server_name *.ratwires.space;
return 404;
}}