問題描述
自己寫了個demo,想放到阿里云的服務(wù)器上跑,阿里云上的環(huán)境是用的鏡像市場里的centos6.9+jdk8+nginx1.12.2,但是還預(yù)裝了一個tomcat,他原先有的demo應(yīng)該是vue放到nginx中,后端用的tomcat,而我的demo用的是springboot,以jar包形式打包,放到服務(wù)器上運(yùn)行前端能訪問,后端也能訪問,但是兩個交互一直是不行,所以不知道是nginx沒配置好還是別的原因
問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法
1.不修改springboot的端口(8081),失敗2.停止tomcat服務(wù),修改springboot端口(8080),失敗
相關(guān)代碼
// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)// 這個是nginx的默認(rèn)配置文件user www www;worker_processes auto;
error_log /data/wwwlogs/error_nginx.log crit;pid /var/run/nginx.pid;worker_rlimit_nofile 51200;
events { use epoll; worker_connections 51200; multi_accept on;}
http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 1024m; client_body_buffer_size 10m; sendfile on; tcp_nopush on; keepalive_timeout 120; server_tokens off; tcp_nodelay on;
fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_intercept_errors on;
#Gzip Compression gzip on; gzip_buffers 16 8k; gzip_comp_level 6; gzip_http_version 1.1; gzip_min_length 256; gzip_proxied any; gzip_vary on; gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6].(?!.*SV1)";
#If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency. open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache_errors on;
default
server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/default;
index index.html index.htm index.jsp;
#error_page 404 /404.html;
#error_page 502 /502.html;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ {
proxy_pass http://127.0.0.1:8080;
include proxy.conf;
}
location ~ /\.ht {
deny all;
}
}
vhost
include vhost/*.conf;}
你期待的結(jié)果是什么?實(shí)際看到的錯誤信息又是什么?
正常的結(jié)果應(yīng)該是能交互,本地還沒嘗試nginx代理vue來訪問后端,普通的功能比如登錄,瀏覽器報錯是OPTIONS http://127.0.0.1:8081/login net::ERR_CONNECTION_REFUSED
2 回答

慕姐8265434
TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個贊
你前端代碼部署在哪里了沒有說清楚,通過瀏覽器報的錯猜測是你前端應(yīng)用調(diào)用接口的地址是127.0.0.1。
127.0.0.1指的是你電腦本機(jī)。你后臺部署在阿里云上,那么這個地址怎么著也不可能是127.0.0.1了。
所以你出問題的地方應(yīng)該就是你前端調(diào)用api的地址有問題。
添加回答
舉報
0/150
提交
取消