专业编程教程与实战项目分享平台

网站首页 > 技术文章 正文

手把手教你nginx解决前端本地跨域问题

ins518 2024-09-17 21:46:16 技术文章 25 ℃ 0 评论

收到很多私信,有许多同学遇到本地开发静态文件,想要调试远程接口的问题,教大家一个解决跨域调试常用的方法。有什么其他问题也欢迎大家关注私信我,看到的会一一解答。

先下载nginx,因为大部分人是windows 开发环境,所以文章介绍的也是windows版本



打开配置文档,新建一个自己的配置文件my.conf。 然后找到conf/nginx.conf 引入my.conf


配置my.conf文件

 server {
        listen       3333;    #监听端口  可以访问localhost:3333
        server_name  localhost; 
				#access_log  logs/host.access.log  main;
				location / {
					root  C:/Users/86183/Desktop/feedback;		# 静态文件路径
					index  index.html index.htm;			# 静态文件首页名字
				}
				location /api/ { 						# 请求路劲是api 开头会自动跳转至 www.baidu.com/api/
						proxy_pass	http://www.baidu.com;  #这里填上服务器地址
				}
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
   }

配置成功,在nginx根目录打开 cmd, 命令行输入:

```

nginx版本:nginx -V

启动:start nginx

快速关闭: nginx -s stop

正常关闭:nginx -s quit

重启:nginx -s reload

```

http://localhost:3333/ 查看网站,Ok啦!!!

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表