첫 번째 서버 블록을 추가하여 www.example.com을 https://example.com으로 리디렉션하려고합니다. 하지만 리디렉션되지 않습니다. SEO 문제와 사용자에 대한 보안 경고를 피하려면 영구적으로 리디렉션되어야합니다. 서버 블록은 443 포트와 인증서 정의에 https
를 활성화 ssl
키워드를 누락 최소한nginx www는 301에서 https로 영구 리디렉션합니다.
<code>
server {
listen 80;
listen 443;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name example.com;
#Password protects the test subdomain
## auth_basic "Restricted Content";
## auth_basic_user_file /etc/nginx/.htpasswd;
# Make site accessible from https://example.com/
server_name example.com;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
location ~ /.well-known {
allow all;
}
location/{
try_files $uri $uri/ /index.php$is_args$query_string;
#try_files $uri $uri/ /index.php?q=$request_uri;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
include fastcgi_params;
}
location ~ \.php$ {
#match actual filename with extension or file not found
#try_files $uri $uri =404;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht
{
# deny all;
#
}
}
</code>
하자 암호화가 나는가 또한 인증서를 추가해야 할 것 같아요, 그래서 * .example.com을 같이 와일드 카드 인증서 표시를 지원하지 않는 것을 www.example.com. 리디렉션 만하고 있습니다. – Gabriel
그래서? : 서버 { 듣기 80 default_server; 듣기 [::] : 80 default_server ipv6only = 켜기; listen 443 ssl http2 default_server; 듣기 [::] : 443 ssl http2 default_server; server_name www.example.com; 에는 snippets/ssl-www.example.com.conf가 포함됩니다. 에는 snippets/ssl-params.conf가 포함됩니다. return 301 $ scheme : //example.com$request_uri; } 서버 { 수신 대기 80 default_server; 듣기 [::] : 80 default_server ipv6only = 켜기; listen 443 ssl http2 default_server; 듣기 [::] : 443 ssl http2 default_server; server_name example.com; – Gabriel