简体   繁体   English

使用 proxypass 从 apache2 访问 localhost

[英]Accessing localhost from apache2 with proxypass

So I am very new to a lot of this but I am trying to build a web server to host my own website.所以我对很多东西都很陌生,但我正在尝试构建一个 web 服务器来托管我自己的网站。 It is currently running on Ubuntu 20.04 from a raspberry pi on my desk.它目前在我桌上的树莓派上运行在 Ubuntu 20.04 上。

I have gone through all the steps to get my .net 5 web app running from the server.我已经完成了所有步骤以使我的 .net 5 web 应用程序从服务器运行。 however when I try to access the site through http://192.168.1.14 I get an odd 307 redirect and it redirects me to https://192.168.1.14:5001 .但是,当我尝试通过http://192.168.1.14访问该站点时,我得到一个奇怪的 307 重定向,它将我重定向到https://192.168.1.14:5001 Of course I also get a Site can not be reached error.当然我也得到一个站点无法访问的错误。

I do have my site.conf file:我确实有我的 site.conf 文件:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName BuildItWithDan
    ServerAlias www.BuildItWithDan
    DocumentRoot /var/www/BuildItWithDan
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ErrorLog /var/log/apache2/error.log
    CustomLog /var/log/apache2/access.log common
</VirtualHost>

and when I run my .net 5 app, i can see that it loads and listens correctly.当我运行我的 .net 5 应用程序时,我可以看到它正确加载和收听。

ubuntu@ubuntu:~$ /home/ubuntu/dotnet-64/dotnet /var/www/BuildItWithDan/BuildItWithDan.Web.dll

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]
      User profile is available. Using '/home/ubuntu/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/ubuntu

So when navigate to http://192.168.1.14 I can see some pings on my service.因此,当导航到http://192.168.1.14时,我可以在我的服务上看到一些 ping。

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://192.168.1.14/ - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://192.168.1.14/ - - - 307 0 - 38.2497ms
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://192.168.1.14/ - -
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/1.1 GET http://192.168.1.14/ - - - 307 0 - 1.6625ms

Maybe something noteworthy.也许有什么值得注意的。 If I remove (or comment out) the ProxyPass lines in the.conf file I then am able to connect to the server with http://192.168.1.14 , but it just gives me a directory listing.如果我删除(或注释掉).conf 文件中的 ProxyPass 行,我就可以使用http://192.168.1.14连接到服务器,但它只是给了我一个目录列表。 Then if I change my DocumentRoot path DocumentRoot /var/www/html This will load the default apache site just fine with the same http://192.168.1.14然后,如果我更改我的 DocumentRoot 路径DocumentRoot /var/www/html这将使用相同的http://192.168.1.14加载默认的 apache 站点

I have also run sudo a2enmod proxy proxy_http as well as a couple others I can not think of.我还运行了sudo a2enmod proxy proxy_http以及其他一些我想不到的。

Module proxy already enabled
Considering dependency proxy for proxy_http:
Module proxy already enabled
Module proxy_http already enabled

Any help would be greatly appreciated!任何帮助将不胜感激!

EDIT : I was able to find these from the logs.编辑:我能够从日志中找到这些。

[Tue Mar 23 21:35:45.053007 2021] [proxy:error] [pid 19685:tid 281472865419664] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:5000 (127.0.0.1) failed
[Tue Mar 23 21:35:45.053198 2021] [proxy_http:error] [pid 19685:tid 281472865419664] [client 80.82.77.192:57200] AH01114: HTTP: failed to make connection to backend: 127.0.0.1

You don't need你不需要

ProxyPreserveHost On

unless your application needs a specific hostname (localhost).除非您的应用程序需要特定的主机名 (localhost)。

Your .net app is listening on localhost:您的 .net 应用正在监听本地主机:

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001

Things might be easier if you bind your .net app on *:5000 and *:5001.如果您将 .net 应用程序绑定到 *:5000 和 *:5001,事情可能会更容易。

The error you posted means the proxy couldn't connect to 127.0.0.1:5000 which usually means the application is not running or responding.您发布的错误意味着代理无法连接到 127.0.0.1:5000,这通常意味着应用程序没有运行或响应。 If you connect from your browser to http://127.0.0.1:5000 you should get a similar error.如果您从浏览器连接到http://127.0.0.1:5000 ,您应该会收到类似的错误。 You first need to fix this problem (which is not related to apache) then setup the proxy pass.您首先需要解决此问题(与 apache 无关),然后设置代理通行证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM