简体   繁体   English

使用http协议运行本地HTML文件

[英]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

http://localhost:8000 HTTP://本地主机:8000

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.

相关问题 从本地协议强制Java文件中的HTTP协议 - Force http protocol in Javascript file from local protocol 可以从通过file:// protocol打开的本地文件访问http(localhost或remote)提供的文件吗? 反之亦然? 怎么实现这个? - Can a file served by http (localhost or remote) be accessed from a local file opened through file:// protocol? And vice versa? How to implement this? 从本地node.js Web服务器运行html / javascript文件 - Running html/javascript file from a local node.js webserver 在文件(file://)协议中运行 Web 服务器 - Running Web Server in File (file://) protocol 通过协议在本地网络上运行批处理文件 - Run batch file via protocol on local network 如何检查网站是通过http或https(协议)运行 - How to check a website is running over http or https (protocol) 我如何*本地*保存由javascript生成的.html文件(在* local * .html页面上运行)? - How can I *locally* save an .html file generated by javascript (running on a *local* .html page)? 本地http服务器已停止运行 - Local http server has stopped running Node.js 网络服务器使用 HTTP 并读取 HTML 文件。 那个HTML文件打不开其他本地文件 - Node.js webserver using HTTP and reading an HTML file. That HTML file cannot open other local files 在HTML页面中使用UNC路径打开file://协议 - Open a file:// protocol with UNC paths in HTML page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM