I want to deploy a Vapor app on my server to use it as backend for my iOS app.
(我想在服务器上部署Vapor应用程序,以将其用作iOS应用程序的后端。)
I'm pretty new to this topic.
(我对这个话题还很陌生。)
The only thing I did before was deploying a Django backend on the same server. (我之前所做的唯一一件事就是在同一服务器上部署Django后端。)
I rebuild my server to set up the Vapor backend. (我重建服务器以设置Vapor后端。)
To begin, I wanted to deploy a Vapor app as basic as possible.
(首先,我想尽可能地部署Vapor应用程序。)
I followed this tutorial (it's short): https://medium.com/@ankitank/deploy-a-basic-vapor-app-with-nginx-and-supervisor-1ef303320726 (我遵循了本教程(简短): https : //medium.com/@ankitank/deploy-a-basic-vapor-app-with-nginx-and-supervisor-1ef303320726)
I followed the steps and didn't get errors.
(我按照步骤进行,没有收到错误。)
The problem is, when I try to call [IP]/hello
like in the tutorial, I get 502 Bad Gateway
as answer.
(问题是,当我尝试像本教程中那样呼叫[IP]/hello
,我得到502 Bad Gateway
作为答案。)
Nginx gives me this error:
(Nginx给我这个错误:)
connect() failed (111: Connection refused) while connecting to upstream, client: [IP], server: _, request: "GET /hello HTTP/1.1", upstream: "http://127.0.0.1:8080/hello", host: "[IP]"
I hope you can help me with this.
(希望您能帮到我。)
:) (:))
Update 1:
(更新1:)
I changed the config to this:
(我将配置更改为此:)
server {
listen 80;
listen [::]:80;
server_name [DOMAIN];
error_log /var/log/[DOMAIN]_error.log warn;
access_log /var/log/[DOMAIN]_access.log;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
large_client_header_buffers 8 32k;
location / {
# redirect all traffic to localhost:8080;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080/;
proxy_redirect off;
proxy_read_timeout 86400;
# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# prevents 502 bad gateway error
proxy_buffers 8 32k;
proxy_buffer_size 64k;
reset_timedout_connection on;
tcp_nodelay on;
client_max_body_size 10m;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|html|mp4)$ {
access_log off;
expires 30d;
root /home/[AppName]/Public;
}
}
Unfortunately I still get this one:
(不幸的是我仍然得到这个:)
2019/12/01 14:48:04 [error] 6801#6801: *1 connect() failed (111: Connection refused) while connecting to upstream, client: [IP], server: [DOMAIN], request: "GET /hello HTTP/1.1", upstream: "http://127.0.0.1:8080/hello", host: [DOMAIN]
Update 2:
(更新2:)
The error was related to this line: proxy_pass http://127.0.0.1:8080/;
(错误与以下行相关: proxy_pass http://127.0.0.1:8080/;
)
I had to change it to this: proxy_pass http://localhost:8080/;
(我必须将其更改为: proxy_pass http://localhost:8080/;
)
It seems like localhost is not the same.
(好像localhost不一样。)
Now I can run the app via "vapor run" and I can access it.
(现在,我可以通过“ vapor run”运行该应用程序,并且可以访问它。)
:) (:))
Big thanks to @imike for all the help!!!
(非常感谢@imike的所有帮助!!!)
ask by ref2111 translate from so