nginx解决静态页面中ajax跨域方案配置

nginx 配置内容

server {

listen 9999;#监听端口

server_name localhost;#域名

add_header Access-Control-Allow-Origin *; # 允许跨域

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root D:/html/index.html;#静态html项目的地址

index index.html;

autoindex off;

}

location /test/ {

#以下为Ajax中跨域配置项

add_header 'Access-Control-Allow-Origin' '*';

add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

add_header 'Access-Control-Allow-Headers' '*';

add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';

proxy_pass http://123.456.789.10:1234;# 测试请求地址为你项目具体请求地址

}

}

nginx 命令:

start nginx 启动nginx

nginx -s stop 快速关闭nginx

nginx -s reload 改变了Nginx相关配置,需要重新加载配置而重载。

html 页面请求

var getUrl='http://127.0.0.1:9999/test/net/testtarget'

$.get(getUrl,param,function(data,status){

console.log(data)

console.log(status)

});

相关推荐
Evan芙10 分钟前
Nginx 安装教程(附Nginx编译安装脚本)
windows·nginx·postgresql
invicinble43 分钟前
nginx的基本认识
运维·nginx
爆肝疯学大模型44 分钟前
http转https,免费快速申请证书并实现nginx配置
nginx·http·https
qinyia1 小时前
通过 Wisdom SSH AI 助手部署和配置 Nginx Web 服务器
人工智能·nginx·ssh
嘻哈baby1 小时前
Nginx反向代理与负载均衡实战指南
运维·nginx·负载均衡
二哈喇子!15 小时前
openFuyao 容器平台快速入门:Nginx 应用部署全流程实操
运维·nginx·openfuyao
beijingliushao19 小时前
103-Spark之Standalone环境测试
大数据·ajax·spark
J2虾虾1 天前
上传文件出现“ 413 Request Entity Too Large“错误
nginx
枫叶梨花1 天前
Nginx HTTPS代理大文件加载失败的排查与解决方案
nginx
albert-einstein1 天前
Nginx越界读取缓存漏洞CVE-2017-7529(参考peiqi文库以及gpt)
gpt·nginx·缓存