【问题标题】:Access a web app (ASP.NET) from another machine using nginx使用 nginx 从另一台机器访问 Web 应用程序 (ASP.NET)
【发布时间】:2020-06-03 14:59:43
【问题描述】:

好吧,我们开始吧。
我在 Azure 中有一个带有 ubuntu 的实例,我正在尝试从这台机器(不是 LocalHost)访问 Web 应用程序。
首先,我安装了所有 dotnet 的东西来制作一个测试应用程序并运行

dotnet new mvc

我在 Azure 机器 localhost:5000 内部检查,此应用测试运行良好。

然后我安装了 nginx 来远程访问我的应用程序。当我访问公共IP时,我可以看到一个nginx页面。

nginx Page

当我访问公共 IP 时,我尝试将 nginx 重定向到我在 Azure Localhost 中运行的 Web 应用程序进行数千次配置。
我尝试过的一种配置是

/etc/nginx/启用站点

server {
    listen 80;
    location / {
            proxy_pass http://localhost:5000;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;

    }
}

有什么想法可以使它起作用吗? 抱歉英语不好

【问题讨论】:

  • 启用站点的配置文件名是否正确?还是只是一个目录?
  • 只是一个目录。此路径中有一个名为 Default 的文件,我发布的配置位于此文件中。感谢您尝试帮助我 msgxman

标签: asp.net nginx remote-access


【解决方案1】:

你错过了server_name参数。

如果这是配置目录中唯一的一个配置,那么还要在监听指令中添加default_server option,如下所示:

server {
    listen 80 default_server;
    server_name  my.domain.com;
    location / {
            proxy_pass http://localhost:5000;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;

    }
}

将my.domain.com更改为您的Azure实例的适当FQDN,这样您不仅可以在浏览器中输入IP地址,还可以使用主机名来发出请求。

并确保您已将该配置包含在 nginx.conf 文件中,例如:

include /etc/nginx/sites-enabled/*;

希望对你有所帮助。

【讨论】:

  • 非常感谢 mgxman。有用。我还必须启用 ufw 并运行 ufw allow 'Nginx Full'。这是这篇文章中的其他内容:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-01
  • 2021-12-26
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多