怎样在服务器端的nginx.conf中增加配置以及解决前端跨域问题
发表于:2024-10-05 作者:千家信息网编辑
千家信息网最后更新 2024年10月05日,怎样在服务器端的nginx.conf中增加配置以及解决前端跨域问题,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。第一步:http {
千家信息网最后更新 2024年10月05日怎样在服务器端的nginx.conf中增加配置以及解决前端跨域问题
怎样在服务器端的nginx.conf中增加配置以及解决前端跨域问题,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
第一步:
http { ...... add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range'; ......}
提示
如果以上都不能解决的话需要把凭证改为true
add_header 'Access-Control-Allow-Credentials' 'true';
那么完整的就是:
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Headers' "Origin, X-Requested-With, Content-Type, Accept"; add_header 'Access-Control-Allow-Headers' 'X-Requested-With'; add_header 'Access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
有些道友用的是phpstudy配置,用上面的结果行不通
那么我测试出新的方式:
server { listen 80; server_name www.crm.com crm.com; root "F:/wwwroot/taobao.com/pc2"; add_header Access-Control-Allow-Origin * always; add_header Access-Control-Allow-Methods * always; add_header Access-Control-Allow-Headers * always; location / { add_header Access-Control-Allow-Origin * always; add_header Access-Control-Allow-Methods * always; add_header Access-Control-Allow-Headers * always; index index.php index.html error/index.html; error_page 400 /error/400.html; error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 500 /error/500.html; error_page 501 /error/501.html; error_page 502 /error/502.html; error_page 503 /error/503.html; error_page 504 /error/504.html; error_page 505 /error/505.html; error_page 506 /error/506.html; error_page 507 /error/507.html; error_page 509 /error/509.html; error_page 510 /error/510.html; include F:/MFCRM/API/pc_v0.2/public/nginx.htaccess; autoindex off; } location ~ \.php(.*)$ { add_header Access-Control-Allow-Origin * always; add_header Access-Control-Allow-Methods * always; add_header Access-Control-Allow-Headers * always; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }}
不知道是环境的原因还是其他的原因,有时候设置一处不起作用。
看完上述内容,你们掌握怎样在服务器端的nginx.conf中增加配置以及解决前端跨域问题的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
问题
配置
原因
前端
服务器
端的
服务
内容
方法
更多
束手无策
为此
作用
凭证
对此
就是
技能
方式
有时候
环境
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
农行广州软件开发中心地址
中指数据库网站流量
网络安全应急组织基本职能
沈阳海诺科技互联网
服务器网络安全风险评估报告
网络安全责任制考核制度
手机网络安全小达人
操作数据库中间件
软件开发怎么算新增变更
华为和东土科技布局工业互联网
云数据库需要分库分表
数据库有由什么组成
重庆网络软件开发流程特点
cds信用违约互换数据库
易点科技 互联网金融
如何正确管理服务器
穿越火线服务器人数已经满
高性能服务器硬盘
网络安全 二级
web网络安全培训机构
企业信息网络安全产品
大连软件开发有哪些学校
网络技术诈骗骗局
数据库模型的设计工具
客房管理数据库课程设计
数据库营销启示
结合自身实际谈谈网络安全
nas服务器怎么装到虚拟机
稳定的计算机软件开发设施
保障网络安全相关制度