Rails 提供 后端 api,默认端口为 3002
vuejs 编写前端
部署采用 puma + nginx + docker
现在使用 docker 部署到阿里云后,配置了 nginx,点击相应的链接可以访问页面,但是刷新该页面,会报错 502:
2020/10/05 03:45:31 [error] 8202#8202: *137 connect() to unix:/home/udasker/udaskweb/tmp/sockets/puma.sock failed (111: Connection refused) while connecting to upstream, client: 185.191.171.23, server: www.udask.net, request: "GET /robots.txt HTTP/1.1", upstream: "http://unix:/home/udasker/udaskweb/tmp/sockets/puma.sock:/50x.html", host: "www.udask.net"
user user_name;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
# multi_accept on;
}
http {
upstream app {
server unix:/home/udasker/udaskweb/tmp/sockets/puma.sock;
}
server {
listen 443 ssl;
server_name www.udask.net udask.net;
ssl on;
ssl_certificate /etc/nginx/cert/udask.pem;
ssl_certificate_key /etc/nginx/cert/udask.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers d...;
ssl_prefer_server_ciphers on;
root /home/udasker/udaskweb/front_web/dist; #这里是vuejs的build文件
try_files $uri/index.html $uri @app;
location ~ ^/api/ {
set $backend "127.0.0.1";
proxy_pass http://$backend:3002; #后端rails服务 使用3002端口
proxy_set_header Real-IP $remote_addr;
proxy_set_header Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header NginX-Proxy true;
proxy_redirect off;
}
location @app {
proxy_pass http://app;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
root /home/udasker/udaskweb/front_web/dist;
autoindex_exact_size on;
autoindex_localtime on;
proxy_read_timeout 240s;
}
}
server {
listen 80;
server_name www.udask.net udask.net;
rewrite ^(.*)$ https://$host$1 permanent;
}
}
以上 nginx 配置哪里出现问题了呢?请大家指导,非常感谢~