web_dev
@web_dev

Nginx и request headers?

Здравствуйте,

есть angular приложение которое положил в
root /var/www/dev;

Приложение отзывается по адресу
http://mysite.com:81
Бекенд лежит по этому адресу.
http://mysite.com:8888

Вопрос, почему не добавляются хедеры? Что не так? Такое впечатление, что nginx все затирает, я погуглил. Нашел пример конфига для моего случая, но ничего не происходит. Все как и было..
Буду благодарен за подсказки.

Вот пример запроса и ответа из хрома.
General:
Request URL:http://mysite.com:8888/profile
Request Method:OPTIONS
Status Code: 200
Remote Address:100.100.100.100:8888
Referrer Policy:no-referrer-when-downgrade

Response Headers:
HTTP/1.1 200
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Access-Control-Allow-Origin: http://mysite.com:81
Vary: Origin
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Headers: content-type, x-auth-token
Access-Control-Expose-Headers: X-Auth-Token
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 3600
Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Content-Length: 0
Date: Fri, 07 Jul 2017 12:09:09 GMT
Connection: close


Request Headers:
OPTIONS /profilel HTTP/1.1
Host: mysite.com:8888
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://mysite.com:81
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Access-Control-Request-Headers: content-type,x-auth-token
Accept: */*
Referer: http://mysite.com:81/
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4


Ну и собственно nginx настройка

server{
  
    listen 81 default_server;
    index index.html;

    root /var/www/dev;
    server_name _;
location / {

     if ($request_method = 'OPTIONS') {
        add_header 'X-Auth-Token' 'TooooooooookeeeennnnnnnnnOPTIONS';
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        #
        # Custom headers and headers various browsers *should* be OK with but aren't
        #
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Auth-Token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        #
        # 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;
     }
     if ($request_method = 'POST') {
        add_header 'X-Auth-Token' 'TooooooooookeeeennnnnnnnnPOST';
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Auth-Token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        add_header 'Access-Control-Expose-Headers' 'DNT,X-Auth-Token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
     }
     if ($request_method = 'GET') {
        add_header 'X-Auth-Token' 'TooooooooookeeeennnnnnnnnGET';
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-Auth-Token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
        add_header 'Access-Control-Expose-Headers' 'DNT,X-Auth-Token,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
     }
}
}


Спасибо.
  • Вопрос задан
  • 2462 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы