AngularJs客户端没有连接到服务器端

时间:2015-11-12 06:38:15

标签: angularjs nginx

问题是客户端无法连接到服务器端。我所知道的问题是发送请求方法OPTIONS而不是GET。看看这些标题

General:

Remote Address:127.0.0.1:9000
Request URL:http://localhost:9000/api/v1/gyms
Request Method:OPTIONS
Status Code:404 Not Found

Response Headers:

view source
Content-Length:26454
Content-Type:text/html; charset=utf-8

Request Headers:

view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, accept-language, authorization, dev
Access-Control-Request-Method:GET
Connection:keep-alive
Host:localhost:9000
Origin:http://localhost
Referer:http://localhost/VTraining
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
X-FirePHP-Version:0.0.6

通用标头应该有GET请求方法。我在nginx上部署了客户端应用程序。

这是我的nginx.conf文件HTTP设置。

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;
client_max_body_size 20m;
server {
      listen 9077;
      server_name localhost 127.0.0.1;
      index index.html;
      root Web/Web/nginx/app/;

      add_header "Access-Control-Allow-Origin" "*";
  add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, PUT, DELETE";
  add_header "Access-Control-Allow-Headers" "X-Filter-Query, Authorization";

   location ~ \.(js|css|png|jpg|jpeg|gif|ico|html|woff|ttf|svg|eot|otf)$ {
      expires 1M;
      access_log off;
      add_header Cache-Control "public";
  }

   location / {
      try_files $uri /index.html;
if ($request_method = OPTIONS ) {
                    add_header Content-Length 0;
                    add_header Content-Type text/plain;
                    add_header Access-Control-Allow-Origin *;
                    add_header Access-Control-Allow-Headers 'origin, x-requested-with, content-type, accept';
                    add_header Access-Control-Allow-Methods 'GET, POST';
                    return 200;
            }
  }    


}

0 个答案:

没有答案
相关问题