收到很多私信,有许多同学遇到本地开发静态文件,想要调试远程接口的问题,教大家一个解决跨域调试常用的方法。有什么其他问题也欢迎大家关注私信我,看到的会一一解答。
先下载nginx,因为大部分人是windows 开发环境,所以文章介绍的也是windows版本
![b010d3f9f44b5b0632b2f65e469934d0.png](https://i-blog.csdnimg.cn/blog_migrate/d8751bbeaa81502c4d7979efb94b5118.jpeg)
下载nginx
![99b928d10f5d75941b622b3c562a7d24.png](https://i-blog.csdnimg.cn/blog_migrate/2c626364fcbc5fcfc7a43a6b6338eaaa.jpeg)
安装后的目录
打开配置文档,新建一个自己的配置文件my.conf。 然后找到conf/nginx.conf 引入my.conf
![d1008fd27e554b20d651a6bea4067a1e.png](https://i-blog.csdnimg.cn/blog_migrate/38531997b50fca2e8df8dcfdab11b382.jpeg)
在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_passhttp://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啦!!!