ZBLOG

nginx: [emerg] directive "add_header" is not terminated by ";" in /www/server/panel/vhost/nginx/192.168.124.131.conf:35 nginx: configuration file /www/server/nginx/conf/nginx.conf test failed location ^~ api/ { proxy_pass http://127....

在你提供的配置中,存在一个语法错误。在第6行的 add_header Access-Control-Allow-Headers '*' 以及第16行的 add_header 'Content-Length'0; 中缺少了分号(;)。

此外,在第14行缺少了一个分号(;),应该修改为 add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';

修改后的代码如下:

location ^~ /api/ {
    proxy_pass http://127.0.0.1:8100/api/;
    add_header 'Access-Control-Allow-Origin' $http_origin;
    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
    add_header 'Access-Control-Allow-Headers' '*';
    
    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Origin' $http_origin;
        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain;charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
    }
}

请注意,根据你的具体需求和Nginx版本,可能需要进一步调整和测试这些配置。确保你的Nginx配置文件符合语法要求,并使用 nginx -t 命令进行测试,以确保没有其他语法错误或冲突。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://sdn.0voice.com/?id=3295

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?