title: Nginx proxy pass 404 error - CORS
body: <p>I have configured a proxy_pass for an JAVA web service to enable cross origin. I can send a post request using the web service URL <a href="http://10.1.200.156:8080/ClientService/passwordReset/" rel="nofollow">http://10.1.200.156:8080/ClientService/passwordReset/</a>, but <a href="http://10.1.200.156/ClientService/passwordReset/" rel="nofollow">http://10.1.200.156/ClientService/passwordReset/</a> gives a 404 error. And client application gives, <code>Response for preflight is invalid (redirect)</code>.
  After searching the web I added <code>proxy_set_header Host $http_host;</code> to the Nginx configuration, but still no luck. Below, the Nginx configuration. Please help.</p>
  
  <pre><code>http {
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
  
      access_log  /var/log/nginx/access.log  main;
  
      sendfile            on;
      tcp_nopush          on;
      tcp_nodelay         on;
      keepalive_timeout   65;
      types_hash_max_size 2048;
  
      include             /etc/nginx/mime.types;
      default_type        application/octet-stream;
  
      include /etc/nginx/conf.d/*.conf;
  
      server {
      listen 80;
      server_name euca-172-16-10-214.eucalyptus.internal;
  
      location /ClientService/passwordReset/ {
          proxy_pass http://10.1.200.156:8080/ClientService/passwordReset/;
  
              if ($request_method = 'OPTIONS') {
                  add_header 'Access-Control-Allow-Origin' '*';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                  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 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Credentials' 'true';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                  }
  
              if ($request_method = 'GET') {
                  add_header 'Access-Control-Allow-Origin' '*';
              add_header 'Access-Control-Allow-Credentials' 'true';
                  add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                  add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                  }
          }
      }
  }
  </code></pre>