我的 html 文件位于 Nginx 的 html 文件夹下,我尝试通过 Angular 向 Play 应用程序发送 $http 请求。play应用在9210端口下,nginx监听80端口(用于查看html文件);我认为问题出在这里,因为不同的端口被视为不同的域。
我的 Nginx 服务器配置是:
listen 80;
listen 443 default ssl;
server_name localhost;
#ssl on;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/nginx/conf/server.key;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
add_header Access-Control-Allow-Origin http://127.0.0.1;
}
Play 中的 routes 文件中的相关部分是:
POST /processReq controllers.Application.processReq()
在角度我的 $http 请求是:
$scope.url = 'http://ec2-50-112-30-246.us-west-2.compute.amazonaws.com:9210/processReq';
$scope.routeReview = function() {
$http.post($scope.url, { "blanCommand": "read reviews() for=\""+$scope.keywords+"\" mode=full"}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$rootScope.reviews = data;
alert('success');
$location.path('/review');
})
.
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
alert('fail');
$location.path('/review');
});
};
我的问题如下;根据要求,我收到 Access-Control-Allow-Origin 错误,配置我的 Web 应用程序的正确方法是什么?
提前谢谢