W
W
web_dev2017-07-07 15:59:25
Nginx
web_dev, 2017-07-07 15:59:25

Nginx and request headers?

Hello,
there is an angular application that I put in the
root /var/www/dev;
Application responds to the address
http://mysite.com:81
The backend is located at this address.
http://mysite.com:8888
The question is why headers are not added? What's wrong? It seems that nginx overwrites everything, I googled it. Found an example config for my case, but nothing happens. Everything is as it was ..
I would be grateful for the tips.
Here is an example request and response from chrome.

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

Well, actually nginx setup
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';
     }
}
}

Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question