经过几天的尝试让这个工作变得非常困难,我可以使用一些帮助。
我有一个运行良好的 Steam API。我创建了一条路线,可以从 http://localhost:8080/backend/returnA 访问它在服务器上的浏览器中。它返回一些 JSON。
我被困的地方是尝试将 Nginx 配置为服务器作为代理。谁能帮我理解 http://localhost:8080/backend/returnA URL 转换为可从 LAN 访问的工作 URL?
我很困惑,因为 Nginx.conf 要求输入根 URL,但我不知道该输入什么。如果我将其留空,则默认为/usr/local/Cellar/nginx/1.15.6/html/backend/returnA/index.html 这显然行不通。如果我将它设置为 Vapor 应用程序目录中的公用文件夹,这也不起作用。在这两种情况下,我都会收到“没有这样的文件或目录”。
我浏览了网上找到的无数 Nginx conf 设置,尝试添加代理位置,但没有任何效果。尝试http://172.16.1.25/backend/returnA/总是从 Nginx 服务器返回 404。
当 Nginx 不提供像 index.html 这样的静态文件,而是重新调整 JSON 时,如何将 Nginx 指向我的 Vapor 路由?
任何帮助深表感谢。
这是配置,经过编辑以包含 Thanh 的代码,旧位置已注释掉:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
server_name 172.16.1.25;
listen 80 default_server;
root /Users/localadmin/Developer/server/MedicapAPI/Public/;
# location @proxy {
# proxy_pass http://127.0.0.1:8080;
# proxy_pass_header Server;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_pass_header Server;
# proxy_connect_timeout 3s;
# proxy_read_timeout 10s;
# }
location / {
proxy_ignore_client_abort on;
proxy_pass http://localhost:8080/;
proxy_redirect off;
}
}
include servers/*;
}
最佳答案
使用这个:
listen 80 default_server;
server_name 172.16.1.25; #ip address of server
它将捕获所有服务器 block 并且:
location / {
proxy_ignore_client_abort on;
proxy_pass http://localhost:8080/;
proxy_redirect off;
}
它将是
proxy_pass
到在端口 8080 中运行的应用程序
关于macos - 将 Nginx 配置为 Vapor API 的代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53440216/