[英]Running local HTML file with http protocol
I have a html file, when I click it, browser window pops up with file:///c:/myhtml.html
. 我有一个html文件,当我点击它时,浏览器窗口弹出
file:///c:/myhtml.html
。 How can I run this file with http protocol scheme, so that the url would be like http://localhost/myhtml
? 如何使用http协议方案运行此文件,以便url类似于
http://localhost/myhtml
?
I don't want to setup a heavyweight webserver. 我不想设置重量级的网络服务器。 Is there any nice and neat solution for this?
这有什么好的和整洁的解决方案吗?
Why I want to do this is, to test my html file under http protocol instead of file:///
protocol on which browsers restrict some functionality. 为什么我要这样做是为了在http协议下测试我的html文件而不是
file:///
protocol,浏览器限制某些功能。
If you have Python installed, type ... 如果安装了Python ,请键入...
python -m SimpleHTTPServer 8000
. python -m SimpleHTTPServer 8000
。
If you have Ruby installed, type ... 如果安装了Ruby ,请键入...
ruby -run -e httpd . -p 8000
... in your cmd.exe or Terminal.app ...在您的cmd.exe或Terminal.app中
This will launch a very simple http-server that serves your current folder as a http-context. 这将启动一个非常简单的http服务器,它将当前文件夹作为http上下文提供。
Resulting URL 生成的URL
I'd suggest you look at nginx . 我建议你看看nginx 。 It's pretty lightweight and easy to configure.
它非常轻巧,易于配置。 It's also well documented (look at the serving static content section for what you've requested).
它也有详细记录 (请查看服务静态内容部分,了解您的要求)。
There are a lot of tutorials online showing how to get started. 网上有很多教程展示如何入门。 You can create a simple web server without much effort.
您可以轻松创建一个简单的Web服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.