【问题标题】:Without specifying a port number inside of a API request how server decided that this request is for port 80 or 443如果没有在 API 请求中指定端口号,服务器如何决定该请求是针对端口 80 还是 443
【发布时间】:2021-07-19 18:25:00
【问题描述】:

我没有在我的 api 端点中提及端口号,但服务器如何决定使用端口 80 或 443 来处理此请求

const {data} = await axios.get('/api/users/currentuser');

【问题讨论】:

  • 相对 URL 与当前页面 URL 组合以创建最终 URL。因此,如果当前页面使用 HTTPS,那么最终 URL 也将使用 HTTPS。

标签: api nginx server ip port


【解决方案1】:

在 NGINX 中使用类似的东西:

server {
  root /var/www/html;
  
  server_name _;

# this is the react/angular fronted application endpoints
  location / {
    try_files $uri $uri/ /index.html;
  }

# this is the api endpoints
  location /api {
    proxy_pass http://127.0.0.1:8000;
  }
}

但是,您没有在问题中明确提到您是否使用 NGINX,但是您在该问题的 5 个标签之一中有 nginx,所以我假设您必须使用 NGINX,所以,我正在回答那个上下文。

【讨论】:

    猜你喜欢
    • 2010-12-01
    • 1970-01-01
    • 2012-09-22
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多