title: Nginx cors setting not working in docker container
body: <p>I'm trying to deploy frontend (angular ) and backend (.net core) through docker compose on linux server. I have created two docker files present in respective file. Here is my <strong>docker.compos.yml</strong> file.</p>
  
  <pre><code>version: '3.4 
    volumes: 
     data:
  
  services:
    api:
      build:
        context: .
        dockerfile: Backend/Dockerfile
      ports:
        - "5000:80"
      depends_on:
        - db
    web:
      build:
        context: .
        dockerfile: Frontend/Dockerfile
      ports:
       - "80:80"
      depends_on:
        - api
    db:
      image: postgres:latest
      volumes: 
       - data:/var/lib/postgresql/data
      environment:
        POSTGRES_USER: "postgres"
        POSTGRES_PASSWORD: "docker_Password"
        POSTGRES_DB: "database_name"
      ports:
        - "5432:5432"
  </code></pre>
  
  <p>I'm using nginx image for serving front end build. Here is the <strong>default.conf</strong> file with basic settings.</p>
  
  <pre><code>server {
      listen       80;
      server_name  localhost;
      location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
          try_files $uri $uri/ /index.html =404;
      }
  }
  </code></pre>
  
  <p>With above configuration,I ran <strong>docker-compose up --build</strong> and I'm able to see my login page (as port 80 is exposed so my url is my server ip). But when I try to login it sends an ajax request to my api service which is running on port 5000, and I got cross origin error as my frontend which is running on port 80 and trying to access a service which is running on port 5000. 
  I wanted to do something that all my request starting with  api path (here in my case it is <strong>{server_ip}/api/login</strong>) should redirect to api service. Is there anything in nginx which is helpful in redirecting request? </p>
  
  <p>I also tried with adding following lines in location block of <strong>default.conf</strong>, but no success.</p>
  
  <blockquote>
    <p>add_header 'Access-Control-Allow-Origin'  '*';</p>
    
    <p>add_header 'Access-Control-Allow-Methods'  'GET, POST, OPTIONS'</p>
  </blockquote>
  
  <p>;</p>