AngularJs客户端未连接到服务器端
问题是客户端无法连接到服务器端。就我所知,问题是发送请求方法AngularJs客户端未连接到服务器端,angularjs,nginx,Angularjs,Nginx,问题是客户端无法连接到服务器端。就我所知,问题是发送请求方法OPTIONS,而不是GET。看看这些标题 概述: Remote Address:127.0.0.1:9000 Request URL:http://localhost:9000/api/v1/gyms Request Method:OPTIONS Status Code:404 Not Found 响应标题: view source Content-Length:26454 Content-Type:text/html; chars
OPTIONS
,而不是GET
。看看这些标题
概述:
Remote Address:127.0.0.1:9000
Request URL:http://localhost:9000/api/v1/gyms
Request Method:OPTIONS
Status Code:404 Not Found
响应标题:
view source
Content-Length:26454
Content-Type:text/html; charset=utf-8
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
请求头:
view source
Content-Length:26454
Content-Type:text/html; charset=utf-8
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
Request方法。我在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;
}
}
}
默认情况下,不需要对服务器选项响应进行特殊覆盖。查看nginx文档也许这个快速搜索有帮助?发送此请求的代码是什么?如果您说方法应该是其他的,那么您可能需要检查启动此请求的代码。您正在使用的是框架吗?Orgin page is
localhost:80
?请求的是localhost:9000
?因此,您需要在CORS服务器上工作的选项(localhost:9000
)您可以使源和目标相同(如localhost:80
)这将避免您需要使选项在localhost:9000
@DarrylMiles工作如何使源和目标相同?你能帮助我吗?