
Laravel API와 NuxtJS(SSR)를 사용하여 프로젝트를 만들었습니다.
Ubuntu(18.04 LTS)를 실행하는 AWS 서버에 배포했습니다. 내 문제는 "example.com" 링크로 이동할 때마다 파일을 다운로드하지만 예를 들어 http:// 또는 https://를 추가할 때마다 정상적으로 작동한다는 것입니다.
내 서버 블록은 다음과 같습니다.
# Default
map $sent_http_content_type $expires {
"text/html" epoch;
"text/html; charset=utf-8" epoch;
default off;
}
server {
# listen [::]:80 ssl http2;
server_name example.com www.example.com;
gzip on;
gzip_types text/plain application/xml text/css application/javascript;
gzip_min_length 1000;
# Logs
access_log /var/log/nginx/example.com_access.log;
error_log /var/log/nginx/example.com_error.log;
location / {
expires $expires;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location ~ /\.{
access_log off;
log_not_found off;
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/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.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 http2;
server_name example.com www.example.com;
return 404; # managed by Certbot
}
답변1
변경하여 수정됨
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 http2;
server_name example.com www.example.com;
return 404; # managed by Certbot
}
에게:
server {
listen 80 default_server;
server_name example.com www.example.com
return 301 https://$host$request_uri
}