为了账号安全,请及时绑定邮箱和手机立即绑定

如何配置nginx文件已达到nginx代理的vue项目访问到jar包形式的springboot工程?

如何配置nginx文件已达到nginx代理的vue项目访问到jar包形式的springboot工程?

四季花海 2019-05-08 12:39:47
问题描述自己写了个demo,想放到阿里云的服务器上跑,阿里云上的环境是用的镜像市场里的centos6.9+jdk8+nginx1.12.2,但是还预装了一个tomcat,他原先有的demo应该是vue放到nginx中,后端用的tomcat,而我的demo用的是springboot,以jar包形式打包,放到服务器上运行前端能访问,后端也能访问,但是两个交互一直是不行,所以不知道是nginx没配置好还是别的原因问题出现的环境背景及自己尝试过哪些方法1.不修改springboot的端口(8081),失败2.停止tomcat服务,修改springboot端口(8080),失败相关代码//请把代码文本粘贴到下方(请勿用图片代替代码)//这个是nginx的默认配置文件userwwwwww;worker_processesauto;error_log/data/wwwlogs/error_nginx.logcrit;pid/var/run/nginx.pid;worker_rlimit_nofile51200;events{useepoll;worker_connections51200;multi_accepton;}http{includemime.types;default_typeapplication/octet-stream;server_names_hash_bucket_size128;client_header_buffer_size32k;large_client_header_buffers432k;client_max_body_size1024m;client_body_buffer_size10m;sendfileon;tcp_nopushon;keepalive_timeout120;server_tokensoff;tcp_nodelayon;fastcgi_connect_timeout300;fastcgi_send_timeout300;fastcgi_read_timeout300;fastcgi_buffer_size64k;fastcgi_buffers464k;fastcgi_busy_buffers_size128k;fastcgi_temp_file_write_size128k;fastcgi_intercept_errorson;#GzipCompressiongzipon;gzip_buffers168k;gzip_comp_level6;gzip_http_version1.1;gzip_min_length256;gzip_proxiedany;gzip_varyon;gzip_typestext/xmlapplication/xmlapplication/atom+xmlapplication/rss+xmlapplication/xhtml+xmlimage/svg+xmltext/javascriptapplication/javascriptapplication/x-javascripttext/x-jsonapplication/jsonapplication/x-web-app-manifest+jsontext/csstext/plaintext/x-componentfont/opentypeapplication/x-font-ttfapplication/vnd.ms-fontobjectimage/x-icon;gzip_disable"MSIE[1-6].(?!.*SV1)";#IfyouhavealotofstaticfilestoservethroughNginxthencachingofthefiles'metadata(nottheactualfiles'contents)cansavesomelatency.open_file_cachemax=1000inactive=20s;open_file_cache_valid30s;open_file_cache_min_uses2;open_file_cache_errorson;defaultserver{listen80;server_name_;access_log/data/wwwlogs/access_nginx.logcombined;root/data/wwwroot/default;indexindex.htmlindex.htmindex.jsp;#error_page404/404.html;#error_page502/502.html;location/nginx_status{stub_statuson;access_logoff;allow127.0.0.1;denyall;}location~.*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)${expires30d;access_logoff;}location~.*\.(js|css)?${expires7d;access_logoff;}location~{proxy_passhttp://127.0.0.1:8080;includeproxy.conf;}location~/\.ht{denyall;}}vhostincludevhost/*.conf;}你期待的结果是什么?实际看到的错误信息又是什么?正常的结果应该是能交互,本地还没尝试nginx代理vue来访问后端,普通的功能比如登录,浏览器报错是OPTIONShttp://127.0.0.1:8081/loginnet::ERR_CONNECTION_REFUSED
查看完整描述

2 回答

?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

你前端代码部署在哪里了没有说清楚,通过浏览器报的错猜测是你前端应用调用接口的地址是127.0.0.1。127.0.0.1指的是你电脑本机。你后台部署在阿里云上,那么这个地址怎么着也不可能是127.0.0.1了。所以你出问题的地方应该就是你前端调用api的地址有问题。
                            
查看完整回答
反对 回复 2019-05-08
  • 2 回答
  • 0 关注
  • 1567 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信