【发布时间】:2023-03-24 17:58:01
【问题描述】:
我卡住了,我不知道如何在nginx 中启用CORS?老实说,我找到了很多在 nginx 中启用CORS 的解决方案,其中之一是https://enable-cors.org/server_nginx.html,但我已经在/etc/nginx/nginx.conf 中添加了这些代码并重新启动nginx 服务器。但我再次尝试在邮递员内部并遵循nginx 引发的错误。
<html>
<head>
<title>405 Not Allowed</title>
</head>
<body bgcolor="white">
<center>
<h1>405 Not Allowed</h1>
</center>
<hr>
<center>nginx/1.12.1</center>
</body>
</html>
请告诉我如何解决它。谢谢。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/test/app/;
# Load configuration files for the default server block.
include /etc/nginx/default/*.conf;
add_header 'Access-Control-Allow-Origin' *;
add_header 'Access-Control-Allow-Methods' 'GET, POST';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
location / {
}
【问题讨论】:
-
请出示您的 nginx.conf 和您的请求
-
@AlexC 我已经编辑了我的问题。
-
您错过了允许方法的选项。
-
@AlexC 仍然无法正常工作
-
@ppshein,请出示您的请求详情