http {
server {
server_name "~^www\.(.*)$" ;
return 301 $scheme://$1$request_uri ;
}
}
server {
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /path/to/server.cert;
ssl_certificate_key /path/to/server.key;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /path/to/server.cert;
ssl_certificate_key /path/to/server.key;
server_name example.com;
<все локации основного домена>
}
server {
server_name mysite.com;
root /var/www/user/data/www/mysite.com;
index index.php;
try_files $uri $uri/ @rewrite;
listen 123.456.789.11;
listen 123.456.789.11 ssl http2;
charset UTF-8;
.....
set $root_path /.......;
ssl_certificate /......;
ssl_certificate_key /......;
......
.....
..........
add_header Strict-Transport-Security "max-age=31536000";
.....
......
if ($scheme = http) {
rewrite ^ https://$http_host$request_uri? permanent;
}
if ($http_host !~ "^mysite.com$"){
rewrite ^(.*)$ https://mysite.com$1 redirect;
}
......
.....
}