Я пытаюсь настроить прокси-сервер ngnix для ретрансляции вызовов локального хоста на сайты SSL.
Вот фрагмент кода, который я использую:
server {
server_name fully-qualified-domain-name.com;
location / {
set $cors '';
if ($http_origin ~ '^https?://(localhost|www\.fully-qualified-domain-name.com)') {
set $cors 'true';
}
if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
# required to be able to read Authorization header in frontend
#add_header 'Access-Control-Expose-Headers' 'Authorization' always;
}
if ($request_method = 'OPTIONS') {
# Tell client that this pre-flight info is valid for 20 days
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_pass http://localhost:3000/;
}
location /api/ {
set $cors '';
if ($http_origin ~ '^https?://(localhost|www\.fully-qualified-domain-name.com\.com)') {
set $cors 'true';
}
if ($cors = 'true') {
add_header 'Access-Control-Allow-Origin' "$http_origin" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
# required to be able to read Authorization header in frontend
#add_header 'Access-Control-Expose-Headers' 'Authorization' always;
}
if ($request_method = 'OPTIONS') {
# Tell client that this pre-flight info is valid for 20 days
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_pass http://localhost:7777/;
}
listen [::]:8080 ssl ipv6only=on;
listen 8080 ssl ;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/fully-qualified-domain-name.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/fully-qualified-domain-name.com.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 = falcon-dev.westeurope.cloudapp.azure.coma) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name fully-qualified-domain-name.com.com;
return 404; # managed by Certbot
}
Явозможность доступа к корневой странице (логин).
Когда я пытаюсь перейти оттуда, я получаю следующую ошибку в браузере:
Доступ к выборке в 'https://fully -qualified-domain-name.com: 8080/ auth / login 'from origin' https://fully -qualified-domain-name.com.com 'заблокировано политикой CORS: Ответ на предварительный запрос не проходит проверку контроля доступа:В запрошенном ресурсе отсутствует заголовок «Access-Control-Allow-Origin».Если непрозрачный ответ соответствует вашим потребностям, установите режим запроса «no-cors», чтобы получить ресурс с отключенным CORS.
Буду признателен за любые указания по решению этой проблемы.