服务器部署项目之后data返回的内容为index.html

问题描述:将前后端项目放在服务器,前端build之后,使用nginx部署前端,使用了nginx代理后端接口,并进行转发,在配置完nginx后发现,前端浏览器中调用接口显示status为200,但是返回的data为build后的index.html,实际上我需要的是调用接口得到的json数据。

项目开发时的技术栈:react+flask+Mysql+redis+nginx

解决方法:index.html显示You need to enable JavaScript to run this app.一开始我以为是浏览器禁用掉了js,经过检查发现不是此问题。在本地运行前后端没有任何问题,服务器上又只修改了nginx,那大概率就是nginx配置时的问题,事实上确实是nginx配置的问题,nginx配置中一开始我写了两个server,我将两个server放在一起之后,便解决了此问题。

 server {
        listen       80; //80修改成你自己监听的端口号
        server_name  baidu.com //baidu.com修改成你监听的域名;
        // 以下为ssl证书配置
        ssl_protocols TLSv1 TLSV1.1 TLSv1.2;
        ssl_certificate /etc/nginx/private/cert.crt; //存放的路径为/etc/nginx/private
        ssl_certificate_key /etc/nginx/private/key.key;
        // 监听的接口
        location / {
                root /root/Project/build; // /root/Project/build替换为你的前端build之后的路径
                index index.html; 
                try_files $uri $uri/ /index.html;
                } 
        location /api { //api替换成你的后端接口,前端发送的请求要为https://www.baidu.com/api
        proxy_pass http://127.0.0.1:5000/api; //在这填写转发的地址,调用后端的接口 
        // https://www,baidu.com/api将会转发到本机(服务器)的http://127.0.0.1:5000/api,需要提            
        // 前将后端运行,接口运行在127.0.0.1:5000。
        add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
        add_header Content-Type "application/json";
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: 在部署Windows Server 2012 R2服务器时,可以按照以下步骤进行操作。首先,访问指定的备用路径 \\10.2.81.29\Files\ISO\OS,并右击2012R2的镜像,选择装载。然后进入虚拟光盘的目录,找到sources文件夹,再进入sxs文件夹。复制完整的路径 F:\sources\sxs。\[1\] 接下来,您需要下载并安装Visual C++ Redistributable for Visual Studio 2015。您可以从Microsoft官方下载中心下载该软件,并直接运行安装程序即可。\[2\] 最后,在访问的public目录下,您会找到一个名为web.config的文件。这个文件用于设置伪静态,其内容如下: <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="OrgPage" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(.*)$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> <defaultDocument> <files> <add value="index.php" /> </files> </defaultDocument> </system.webServer> </configuration> 以上是Windows Server 2012 R2服务器部署的一般步骤和相关配置。希望对您有所帮助。 #### 引用[.reference_title] - *1* [Windows Server 2012 R2 服务器IIs环境部署](https://blog.csdn.net/xulong5000/article/details/96115283)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [windows server 2012 r2 服务器部署tp6 项目](https://blog.csdn.net/qq_41408081/article/details/123211735)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值