godaddy运行asp_在GoDaddy最便宜的共享Linux主机上运行ASP.NET Core-不要在家中尝试

godaddy运行asp

godaddy运行asp

First, a disclaimer. Don't do this. I did this to test a theory and to prove a point. ASP.NET Core and the .NET Core that it runs on are open source and run pretty much anywhere. I wanted to see if I could run an ASP.NET Core site on GoDaddy's cheapest hosting ($3, although it scales to $8) that basically supports only PHP. It's not a full Linux VM. It's locked-down and limited. You don't have root. You are missing most tools you'd expect you'd have.

首先,免责声明。 不要这样我这样做是为了检验理论并证明观点。 它运行的ASP.NET Core和.NET Core是开源的,几乎可以在任何地方运行。 我想看看是否可以在基本上仅支持PHP的GoDaddy最便宜的托管服务器上运行ASP.NET Core网站(价格为3美元,但可以扩展为8美元)。 它不是完整Linux VM。 它被锁定并受到限制。 您没有根。 您缺少了您期望拥有的大多数工具。

BUT.

但。

I wanted to see if I could get ASP.NET Core running on it anyway. Maybe if I do, they (and other inexpensive hosts) will talk to the .NET team, learn that ASP.NET Core is open source and could easily run on their existing infrastructure.

我想看看我是否还能在上面运行ASP.NET Core。 也许我愿意,他们(和其他廉价的主机)将与.NET团队进行对话,了解ASP.NET Core是开源的,并且可以轻松地在其现有基础结构上运行。

AGAIN: Don't do this. It's hacky. It's silly. But it's hella cool. IMHO. Also, big thanks to Tomas Weinfurt for his help!

再次:不要这样做。 太过分了真傻但这真酷。 恕我直言。 另外,非常感谢Tomas Weinfurt的帮助!

First, I went to GoDaddy and signed up for their cheap hosting. Again, not a VM, but their shared one. I also registered supercheapaspnetsite.com as well. They use a cPanel-based web management system that doesn't really let you do anything. You can turn on SSH, do some PHP stuff, and generally poke around, but it's not exactly low-level.

首先,我去了GoDaddy并注册了他们的廉价主机。 同样,不是VM,而是他们共享的VM。 我也注册了supercheapaspnetsite.com 他们使用基于cPanel的Web管理系统,实际上并不能让您做任何事情。 您可以打开SSH,执行一些PHP任务,并且通常在其中四处摸索,但这并不是完全底层的。

First I ssh (shoosh!) in and see what I'm working with. I'm shooshing with Ubuntu on Windows 10 feature, that every developer should turn on. It's makes it really easy to work with Linux hosts if you're starting from Linux on Windows 10.

首先,我使用ssh(嘘!),看看我在用什么。 我正在使用Windows 10功能上的Ubuntu,每个开发人员都应打开电源。 如果您是从Windows 10上Linux开始的,那么使用Linux主机确实非常容易。

secretname@theirvmname [/proc]$ cat version
Linux version 2.6.32-773.26.1.lve1.4.46.el6.x86_64 (mockbuild@build.cloudlinux.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Tue Dec 5 18:55:41 EST 2017
secretname@theirvmname [/proc]$

OK, looks like Red Hat, so CentOS 6 should be compatible.

好的,看起来像Red Hat,所以CentOS 6应该兼容。

I'm going to use .NET Core 2.1 (which is in preview now!) and get the SDK at https://www.microsoft.com/net/download/all and install it on my Windows machine where I will develop and build the app. I don't NEED to use Windows to do this, but it's the laptop I have and it's also nice to know I can build on Windows but target CentOS/RHEL6.

我将使用.NET Core 2.1(现在正在预览!),并通过https://www.microsoft.com/net/download/all获取SDK,并将其安装在将要开发和运行的Windows计算机上。生成应用。 我不需要使用Windows来执行此操作,但是这是我拥有的笔记本电脑,也很高兴知道我可以在Windows上构建但以CentOS / RHEL6为目标

Next I'll make a new ASP.NET site with

接下来,我将创建一个新的ASP.NET网站,

dotnet new razor

and then I'll publish a self-contained version like this:

然后我将发布一个独立的版本,如下所示:

dotnet publish -r rhel.6-x64

And those files will end up in a folder like \supercheapaspnetsite\bin\Debug\netcoreapp2.1\rhel.6-x64\publish\

这些文件最终会放在\ supercheapaspnetsite \ bin \ Debug \ netcoreapp2.1 \ rhel.6-x64 \ publish \

NOTE: You may need to add the NuGet feed for the dailies for this .NET Core preview in order to get the RHEL6 runtime downloaded during this local publish.

注意:您可能需要为此.NET Core预览的日报添加NuGet供稿,以便在此本地发布期间下载RHEL6运行时。

Then I used WinSCP (or whatever FTP/SCP client you like, rsync, etc) to get the files over to the ~/www folder on your GoDaddy shared site. Then I

然后,我使用WinSCP(或您喜欢的任何FTP / SCP客户端,rsync等)将文件移到GoDaddy共享站点上的〜/ www文件夹中。 然后我

chmod +x ./supercheapasnetsite

to make it executable. Now, from my ssh session at GoDaddy, let's try to run my app!

使它可执行。 现在,在GoDaddy的ssh会话中,让我们尝试运行我的应用程序!

secretname@theirvmname [~/www]$ ./supercheapaspnetsite
Failed to load hb, error: libunwind.so.8: cannot open shared object file: No such file or directory
Failed to bind to CoreCLR at '/home/secretname/public_html/libcoreclr.so'

Of course it couldn't be that easy, right? .NET Core wants the unwind library (shared object) and it doesn't exist on this locked down system.

当然不可能那么容易,对吧? .NET Core需要展开库(共享对象),并且在此锁定的系统上不存在。

AND I don't have yum/apt/rpm or a way to install it right?

而且我没有yum / apt / rpm或正确的安装方式?

I could go looking for tar.gz file somewhere like this http://download.savannah.nongnu.org/releases/libunwind/ but I need to think about versions and make sure things line up. Given that I'm targeting CentOS6, I should start here https://centos.pkgs.org/6/epel-x86_64/libunwind-1.1-3.el6.x86_64.rpm.html and download libunwind-1.1-3.el6.x86_64.rpm.

我可以在http://download.savannah.nongnu.org/releases/libunwind/这样的地方查找tar.gz文件,但我需要考虑版本并确保所有内容都对齐。 鉴于我的目标是CentOS6,我应该从这里开始https://centos.pkgs.org/6/epel-x86_64/libunwind-1.1-3.el6.x86_64.rpm.html并下载libunwind-1.1-3.el6 .x86_64.rpm。

I need to crack open that rpm file and get the library. RPM packages are just headers on top of a CPIO archive, so I can apt-get install rpm2cpio from my local Ubuntu instances (on Windows 10). Then from /mnt/c/users/scott/Downloads (where I downloaded the file) I will extract it.

我需要打开该rpm文件并获取该库。 RPM软件包只是CPIO存档顶部的标头,因此我可以从本地Ubuntu实例(在Windows 10上)apt-get install rpm2cpio。 然后从/ mnt / c / users / scott / Downloads(我下载文件的位置)中将其解压缩。

rpm2cpio ./libunwind-1.1-3.el6.x86_64.rpm | cpio -idmv

There they are.

他们在那里。

image

This part is cool. Even though I have these files, I don't have root or any way to "install" them. However I could either export/use the LD_LIBRARY_PATH environment variable to control how libraries get loaded OR I could put these files in $ORIGIN/netcoredeps. You can read more about Self Contained Linux Applications on .NET Core here.

这部分很酷。 即使我有这些文件,也没有root或“安装”它们的任何方法。 但是,我可以导出/使用LD_LIBRARY_PATH环境变量来控制如何加载库,也可以将这些文件放在$ ORIGIN / netcoredeps中。 您可以在此处阅读有关.NET Core上的自包含Linux应用程序的更多信息。

The main executable of published .NET Core applications (which is the .NET Core host) has an RPATH property set to $ORIGIN/netcoredeps. That means that when Linux shared library loader is looking for shared libraries, it looks to this location before looking to default shared library locations. It is worth noting that the paths specified by the LD_LIBRARY_PATHenvironment variable or libraries specified by the LD_PRELOAD environment variable are still used before the RPATH property. So, in order to use local copies of the third-party libraries, developers need to create a directory named netcoredeps next to the main application executable and copy all the necessary dependencies into it.

已发布的.NET Core应用程序(即.NET Core主机)的主要可执行文件的RPATH属性设置为$ORIGIN/netcoredeps 。 这意味着,当Linux共享库加载程序正在寻找共享库时,它将先查找该位置,然后再查找默认的共享库位置。 值得注意的是, LD_LIBRARY_PATH环境变量指定的路径或LD_PRELOAD环境变量指定的库仍在RPATH属性之前使用。 因此,为了使用第三方库的本地副本,开发人员需要在主应用程序可执行文件旁边创建一个名为netcoredeps的目录,并将所有必需的依赖项复制到该目录中。

At this point I've added a "netcoredeps" folder to my public folder, and then copied it (scp) over to GoDaddy. Let's run it again.

此时,我已将“ netcoredeps”文件夹添加到我的公用文件夹,然后将其(scp)复制到GoDaddy。 让我们再次运行它。

secretname@theirvmname [~/www]$ ./supercheapaspnetsite
FailFast: Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.

   at System.Environment.FailFast(System.String)
   at System.Globalization.GlobalizationMode.GetGlobalizationInvariantMode()
   at System.Globalization.GlobalizationMode..cctor()
   at System.Globalization.CultureData.CreateCultureWithInvariantData()
   at System.Globalization.CultureData.get_Invariant()
   at System.Globalization.CultureInfo..cctor()
   at System.StringComparer..cctor()
   at System.AppDomain.InitializeCompatibilityFlags()
   at System.AppDomain.Setup(System.Object)
Aborted

Ok, now it's complaining about ICU packages. These are for globalization. That is also mentioned in the self-contained-linux apps docs and there's a precompiled binary I could download. But there's options.

好的,现在它正在抱怨ICU软件包。 这些是为了全球化。 自包含Linux应用程序文档中也提到了这一点,我可以下载一个预编译的二进制文件。 但是有选择。

If your app doesn't explicitly opt out of using globalization, you also need to add libicuuc.so.{version}, libicui18n.so.{version}, and libicudata.so.{version}

如果您的应用没有明确选择不使用全球化,则还需要添加libicuuc.so.{version}libicui18n.so.{version}libicudata.so.{version}

I like "opt-out" so I don't have to go dig these ups (although I could) so I can either set the CORECLR_GLOBAL_INVARIANT env var to 1, or I can add System.Globalization.Invariant = true to supercheapaspnetsite.runtimeconfig.json, which I'll do with just to be obnoxious. ;)

我喜欢“选择退出”,因此不必(尽管可以)进行挖掘,因此可以将CORECLR_GLOBAL_INVARIANT env var设置为1,也可以将System.Globalization.Invariant = true添加到supercheapaspnetsite.runtimeconfig .json,我将这样做只是为了令人讨厌。 ;)

When I run it again I get another complained about libuv. Yet another shared library that isn't installed on this instance. I could  go get it and put it in netcoredeps OR since I'm using the .NET Core 2.1, I could try something new. There were some improvements made in .NET Core 2.1 around sockets and http performance. On the client side, these new managed libraries are written from the ground up in managed code using the new high-performance Span<T> and on the server-side I could use Kestrel's (Kestrel is the .NET Core webserver) experimental UseSockets() as they are starting to move that over.

当我再次运行它时,我再次抱怨libuv。 尚未在此实例上安装的另一个共享库。 我可以把它放到netcoredeps中,或者因为我使用的是.NET Core 2.1,所以我可以尝试一些新的东西。 .NET Core 2.1在套接字和http性能方面进行了一些改进。 在客户端,这些新的托管库是使用新的高性能Span <T>从头开始以托管代码编写的,而在服务器端,我可以使用Kestrel的(Kestrel是.NET Core网络服务器)实验UseSockets( ),因为他们开始将其移开。

In other words, I can bypass libuv usage entirely by changing my Program.cs to use the use UseSockets() like this.

换句话说,我可以通过将Program.cs更改为使用useUseSockets()来完全绕开libuv的用法。

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
     WebHost.CreateDefaultBuilder(args)
     .UseSockets()
     .UseStartup<Startup>();

Let's run it again. I'll add the ASPNETCORE_URLS environment variable and set it to a high port like 8080. Remember, I'm not admin so I can't use any port under 1024.

让我们再次运行它。 我将添加ASPNETCORE_URLS环境变量并将其设置为8080等高端口。请记住,我不是admin,所以不能使用1024以下的任何端口。

secretname@theirvmname [~/www]$ export ASPNETCORE_URLS="http://*:8080"
secretname@theirvmname [~/www]$ ./supercheapaspnetsite
Hosting environment: Production
Content root path: /home/secretname/public_html
Now listening on: http://0.0.0.0:8080
Application started. Press Ctrl+C to shut down.

Holy crap it actually started.

它实际上开始了。

Ok, but I can't access it from supercheapaspnetsite.com:8080 because this is GoDaddy's locked down managed shared hosting. I can't just open a port or forward a port in their control panel.

好的,但是我无法从supercheapaspnetsite.com:8080访问它,因为这是GoDaddy锁定的托管共享主机。 我不能只是在其控制面板中打开端口或转发端口。

But. They use Apache, and that has the .htaccess file!

但。 他们使用Apache,并且具有.htaccess文件!

Could I use mod_proxy and try this?

我可以使用mod_proxy尝试一下吗?

ProxyPassReverse / http://127.0.0.1:8080/

Looks like no, they haven't turned this on. Likely they don't want to proxy off to external domains, but it'd be nice if they allowed localhost. Bummer. So close.

好像不,他们还没有打开。 可能他们不想代理到外部域,但是如果允许本地主机,那就太好了。 笨蛋很近。

Fine, I'll proxy the traffic myself. (Not perfect, but this is all a spike)

好的,我自己代理流量。 (虽然不完美,但这只是一个峰值)

RewriteRule ^(.*)$  "show.php" [L]

Cool, now a cheesy proxy goes in show.php.

太酷了,现在show.php中有一个俗气的代理。

<?php
$site = 'http://127.0.0.1:8080';
$request = $_SERVER['REQUEST_URI'];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $site . $request);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
$f = fopen("headers.txt", "a");
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_STDERR, $f);
    #don't output curl response, I need to strip the headers.
    #yes I know I can just CURLOPT_HEADER, false and all this 
    # goes away, but for testing we log headers
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$hold = curl_exec($ch);

#strip headers
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($hold, 0, $header_size);
$response = substr($hold, $header_size);
$headerArray = explode(PHP_EOL, $headers);

echo $response; #echo ourselves. Yes I know curl can do this for us.
?>

Cheesy, yes. Works for GET? Also, yes. This really is Apache's job, not ours, but kudos to Tomas for this evil idea.

俗气,是的。 适用于GET? 还可以这确实是Apache的工作,不是我们的工作,而是Tomas对于这个邪恶主意的荣誉。

An ASP.NET Core app at a host that doesn't support it

Boom. How about another page at /about? Yes.

繁荣。 / about的另一页怎么样? 是。

Another page with ASP.NET Core at a host that doesn't support it

Lovely. But I had to run the app myself. I have no supervisor or process manager (again this is already handled by GoDaddy for PHP but I'm in unprivileged world.) Shooshing in and running it is a bad idea and not sustainable. (Well, this whole thing is not sustainable, but still.)

可爱。 但是我必须自己运行该应用程序。 我没有主管或流程经理(同样,GoDaddy已经为PHP处理过,但是我处于无特权的世界中。)Shooshing进入并运行它是一个坏主意,并且不可持续。 (嗯,这整个事情是不可持续的,但仍然是可持续的。)

We could copy "screen" over and start it up and detach like use screen ./supercheapaspnet app, but again, if it crashes, no one will start it. We do have crontab, so for now, we'll launch the app on a schedule occasionally to do a health check and if needed, keep it running. Also added a few debugging tools in ~/bin:

我们可以复制“屏幕”并将其启动,然后像使用screen ./supercheapaspnet应用程序那样将其分离,但是同样,如果崩溃,则没人会启动它。 我们确实有crontab,所以现在,我们偶尔会按计划启动该应用程序以进行运行状况检查,并在需要时保持其运行。 在〜/ bin中还添加了一些调试工具:

secretname@theirvmname [~/bin]$ ll
total 304
drwxrwxr-x  2    4096 Feb 28 20:13 ./
drwx--x--x 20    4096 Mar  1 01:32 ../
-rwxr-xr-x  1  150776 Feb 28 20:10 lsof*
-rwxr-xr-x  1   21816 Feb 28 20:13 nc*
-rwxr-xr-x  1  123360 Feb 28 20:07 netstat*

All in all, not that hard. ASP.NET Core and .NET Core underneath it can run pretty much anywhere, just like PHP, Python, whatever.

总而言之,并不难。 它下面的ASP.NET Core和.NET Core几乎可以在任何地方运行,就像PHP,Python一样。

If you're a host and you want to talk to someone at Microsoft about setting up ASP.NET Core shared hosting, email Sourabh.Shirhatti@microsoft.com and talk to them! If you are GoDaddy, I apologize, and you should also email. ;)

如果您是主持人,并且想与Microsoft的某人讨论如何设置ASP.NET Core共享宿主,请给Sourabh.Shirhatti@microsoft.com发送电子邮件并与他们联系! 如果您是GoDaddy,很抱歉,您也应该发送电子邮件。 ;)

翻译自: https://www.hanselman.com/blog/running-aspnet-core-on-godaddys-cheapest-shared-linux-hosting-dont-try-this-at-home

godaddy运行asp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值