Simplest way to host html [duplicate]

让人想犯罪 __ 提交于 2019-12-10 23:42:03

问题


What is the simplest way to host an HTML page over LAN?

I literally just need to have like 5 lines of HTML, so I don't want to download and setup an Apache server. I just want to know the fastest/simplest way to do this on Windows, or I can also use one of my Linux virtual machines if it's faster.


回答1:


Since you need a web server for testing and no heavy concurrent use is expected, I'll just keep it simple.

Please note that both solutions are very simple but not very secure, use them for development purposes but don't rely on neither of them for anything barely similar to a stable (people would say "production") server.

Navigate to the directory where your HTML file is located using cmd.exe, then issue:

Using Python

python -m SimpleHTTPServer

A HTTP server will be started on port 8000. Should you need a different port, just specify it:

python -m SimpleHTTPServer 8080

SimpleHTTPServer is part of the "batteries included": you will not need to install any extra package, apart from the Python interpreter, of course.

Python comes already installed on most Linux distributions, so switching to Linux might be simpler than install Python on Windows, although that boils down to downloading and running an installer.

Using PHP 5.4 or above

php -S 0.0.0.0:8080

This will also process PHP scripts, but HTML resources will be served fine.




回答2:


Use netcat, or nc:

:top
nc -l -p 80 -q 1 < index.html
goto top

It's a simple binary without any installation. It doesn't do CGI or PHP or anything, but it can sure dish up 5 lines of HTML.

Actually, if you use the "k" (keep-alive) option you can remove the loop, and make it simpler:

nc -kl 80 < index.html



回答3:


http://www.lighttpd.net/ is pretty light weight and easy to get running.




回答4:


I recently used mongoose for a similar purpose. It supports Windows. From the homepage:

Mongoose executable does not depend on any external library or configuration. If it is copied to any directory and executed, it starts to serve that directory on port 8080. If some additional config is required - for example, different listening port or IP-based access control, then a mongoose.conf file with respective options (see example) can be created in the same directory where executable lives. This makes Mongoose perfect for all sorts of demos, quick tests, file sharing, and Web programming.

Download the windows exe (no need to install) from here , save it on the folder where your html file is and execute it. Check the image below to know how to start the server:

After selecting Start Browser on Port 8080 your browser will open automatically displaying the contents of the folder.



来源:https://stackoverflow.com/questions/21321042/simplest-way-to-host-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!