TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Big list of HTTP static server one-liners

282 pointsby raytracerabout 4 years ago

34 comments

satyanashabout 4 years ago
The ruby one with the -run option is a bit nonintuitive in how it works.<p><pre><code> $ ruby -run -ehttpd . -p8000 </code></pre> The -r option requires un.rb[1] which is a file full of convenience functions, such as httpd in this example. Classic Ruby.<p>Given that go has popularized long args with a single hyphen (-name etc), it is easy to mistake -run as an option by itself.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;ruby&#x2F;ruby&#x2F;blob&#x2F;master&#x2F;lib&#x2F;un.rb#L323" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ruby&#x2F;ruby&#x2F;blob&#x2F;master&#x2F;lib&#x2F;un.rb#L323</a>
评论 #27139846 未加载
评论 #27147174 未加载
评论 #27141654 未加载
lipanskiabout 4 years ago
My favourite is thttpd [1] which is super tiny, battle-tested and actually meant for the job (and only this job). It&#x27;s available as a package on most Linux distros.<p>Serving a static folder `&#x2F;static` on port `3000` as user `static-user` and with cache headers set to 60 seconds would go like this:<p><pre><code> thttpd -D -h 0.0.0.0 -p 3000 -d &#x2F;static -u static-user -l - -M 60 </code></pre> Even if you&#x27;ve got Python lying around on every Ubuntu server, I still don&#x27;t get why you wouldn&#x27;t use something leaner to serve your static files, as long as it&#x27;s easy to install&#x2F;configure. Same goes for most of the runtimes in that list.<p>[1] <a href="https:&#x2F;&#x2F;www.acme.com&#x2F;software&#x2F;thttpd&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.acme.com&#x2F;software&#x2F;thttpd&#x2F;</a>
评论 #27141727 未加载
评论 #27141686 未加载
评论 #27147020 未加载
评论 #27146352 未加载
FriedrichNabout 4 years ago
I often use netcat to test stuff locally.<p><pre><code> while true; do cat index.html | nc -l 9999 -q 1; echo -e &quot;\n---&quot;; done</code></pre>
评论 #27142786 未加载
kevincoxabout 4 years ago
Note that a lot of these bind to 0.0.0.0 by default. This has caused me surprises in the past as I was failing to connect to a host that is available over IPv6. Sometimes it was even intermittent as I would sometime resolve to the IPv4 and sometimes get the IPv6 and fail.<p>For python3 this is easily remedied.<p><pre><code> python -m http.server -b :: </code></pre> On most OS configurations this will listen on both IPv4 and IPv6.<p>Or for when you only need local access:<p><pre><code> python -m http.server -b localhost</code></pre>
评论 #27141657 未加载
chrismorganabout 4 years ago
(2013). There are many comments since then providing more alternatives, many of which didn’t exist back in 2013, but the article itself hasn’t been touched since 2013-07-07.
评论 #27141196 未加载
mradminabout 4 years ago
Some of these are multi-liners that can be converted to one-liners. For example I believe &quot;npx&quot; can be used for all the node examples for example &quot;npx http-server -p 6007 .&#x2F;root&quot;<p>[edit] ahh i see this is called out in the gist comments
jfjfhvhfhfhfhfhabout 4 years ago
$ emrun --port 8000 . # Handles WASM; most others don&#x27;t.[1]<p>[1] Emscripten&#x27;s emsdk includes emrun, which actually serves WASM files with the correct MIME type out-of-the-box, unlike the python2 and python3 servers and most others.
评论 #27140486 未加载
abhishekjhaabout 4 years ago
Isn&#x27;t python&#x27;s server blocking? If you make two requests simultaneously, one of them will have to wait.
评论 #27140412 未加载
评论 #27141864 未加载
antiheroabout 4 years ago
If you have npm installed then simply doing<p><pre><code> npx serve </code></pre> is very easy
评论 #27141545 未加载
评论 #27142943 未加载
eatonphilabout 4 years ago
Similarly here&#x27;s a nice list of reverse shell one liners <a href="https:&#x2F;&#x2F;github.com&#x2F;swisskyrepo&#x2F;PayloadsAllTheThings&#x2F;blob&#x2F;master&#x2F;Methodology%20and%20Resources&#x2F;Reverse%20Shell%20Cheatsheet.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;swisskyrepo&#x2F;PayloadsAllTheThings&#x2F;blob&#x2F;mas...</a>
punnerudabout 4 years ago
How many of these support the partial file loading? I know that Python don’t (I have been working on support for it).<p>This would make SQLite example supported: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27016630" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27016630</a>
评论 #27140408 未加载
xaduhaabout 4 years ago
Only one mention of socat, nothing does ad-hoc nonsense that you probably would never use again like socat.<p>&gt; socat TCP4-LISTEN:50000,fork EXEC:&#x2F;usr&#x2F;bin&#x2F;ifconfig<p>&gt; curl --http0.9 localhost:50000<p>Hmmm, does http v0.9 count?
评论 #27140826 未加载
toxikabout 4 years ago
Many of these are so complex you could just say nginx -c &lt;&lt;&lt;(config goes here) is a one liner
bawolffabout 4 years ago
Weird to call these one liners, they&#x27;re just invocation commands.<p>By that logic, apache is a one-liner.
评论 #27142115 未加载
评论 #27140727 未加载
评论 #27140704 未加载
xonixabout 4 years ago
My take on this [1]. Explanation article [2]. In fact the use-case I addressed was slightly different (explained in the article) and later I found the similar tool [3] which probably is more powerful.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;xonixx&#x2F;serv" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;xonixx&#x2F;serv</a><p>[2] <a href="https:&#x2F;&#x2F;medium.com&#x2F;cmlteam&#x2F;develop-a-utility-on-graalvm-cc160feafc19" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;cmlteam&#x2F;develop-a-utility-on-graalvm-cc16...</a><p>[3] <a href="https:&#x2F;&#x2F;github.com&#x2F;schollz&#x2F;croc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;schollz&#x2F;croc</a>
gunnarmorlingabout 4 years ago
It will be a one-liner in Java soon too, once JEP 408 (&quot;simple web server&quot;) has landed. In the meantime, this will do:<p><pre><code> jbang webster@gunnarmorling </code></pre> This launches Vert.x, publishing the current directory, via the JBang launcher. Source code is here if you want to see what you actually run: <a href="https:&#x2F;&#x2F;github.com&#x2F;gunnarmorling&#x2F;jbang-catalog&#x2F;blob&#x2F;master&#x2F;webster.java" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gunnarmorling&#x2F;jbang-catalog&#x2F;blob&#x2F;master&#x2F;w...</a>
divbzeroabout 4 years ago
There is also devd: [1]<p><pre><code> devd . </code></pre> [1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;cortesi&#x2F;devd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cortesi&#x2F;devd</a>
henearkrabout 4 years ago
Anybody has a one-liner allowing CORS (e.g. through options)?<p>That would be utterly convenient to quickly test multithread WASM applications...<p>I&#x27;m currently using ExpressJS for that, but it feels overkill..
评论 #27140492 未加载
评论 #27141201 未加载
评论 #27141191 未加载
tngranadosabout 4 years ago
I wrote a zsh function[1] that runs an http server using ruby, php or python (2 and 3) depending on what&#x27;s available in the system.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tngranados&#x2F;dotfiles&#x2F;blob&#x2F;0ebdc12f2454061a113846fe8e2079e9b6258068&#x2F;zshrc#L57-L75" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tngranados&#x2F;dotfiles&#x2F;blob&#x2F;0ebdc12f2454061a...</a>
SbEpUBz2about 4 years ago
I&#x27;ve started using darkhttpd[1] recently, it&#x27;s simple and compiles quickly to one binary, it supports directory listings and supports range requests.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;emikulic&#x2F;darkhttpd" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;emikulic&#x2F;darkhttpd</a>
conradludgateabout 4 years ago
I&#x27;m a big fan of miniserve[0]. It can do files, directories (including on the fly tgz or zip downloading), authentication and upload<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;svenstaro&#x2F;miniserve" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;svenstaro&#x2F;miniserve</a>
MuffinFlavoredabout 4 years ago
<a href="https:&#x2F;&#x2F;gist.github.com&#x2F;willurd&#x2F;5720255#http-server-nodejs" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;willurd&#x2F;5720255#http-server-nodejs</a><p>You could do `npx http-server` I believe.
config_ymlabout 4 years ago
I use busybox httpd to run my blog via cloud run. It’s a fun setup, using a multistage dockerfile to build the static pages and then create a super small busybox image which just serves those pages.
mbellabout 4 years ago
What I use for https:<p><pre><code> $ ruby -r webrick&#x2F;https -e &quot;WEBrick::HTTPServer.new(Port: 9001, DocumentRoot: &#x27;.&#x27;, SSLEnable: true, SSLCertName: [%w[CN localhost]]).start&quot;</code></pre>
StapleHorseabout 4 years ago
Is there a way of doing that in a Windows without installing anything?
评论 #27140392 未加载
评论 #27140176 未加载
评论 #27142959 未加载
1vuio0pswjnm7about 4 years ago
Missing:<p><pre><code> nghttpd -v -d &#x2F;home&#x2F;user&#x2F;www -a 127.0.0.1 443 &#x2F;home&#x2F;user&#x2F;demoCA&#x2F;serverkey.pem &#x2F;home&#x2F;user&#x2F;demoCA&#x2F;servercert.pem</code></pre>
TheRealPomaxabout 4 years ago
now please also do one for https, no one wants to deal with the cert hassle when they just need a temporary https server for working with some local content.
majkinetorabout 4 years ago
Powershell: Start-PodeStaticServer<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Badgerati&#x2F;Pode" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Badgerati&#x2F;Pode</a>
habitueabout 4 years ago
Wow, didn&#x27;t realize this was started in 2013
tannhaeuserabout 4 years ago
<p><pre><code> $ sthttpd&#x2F;sbin&#x2F;thttpd -i thttpd.pid -l `pwd`&#x2F;access.log -p 8080 -c &#x27;&#x2F;bin&#x2F;*&#x27;</code></pre>
fouronnes3about 4 years ago
What&#x27;s a good one that serves gzip assets if they exist? I&#x27;m looking for a way to serve a webpack prod build.
评论 #27140837 未加载
评论 #27146208 未加载
评论 #27140188 未加载
zachroseabout 4 years ago
Are that any that can serve the same index.html file to any request with an Accept: text&#x2F;html header?
yuvadamabout 4 years ago
I&#x27;m always surprised that nginx doesn&#x27;t have a nice way to run as a single-liner command.
评论 #27140324 未加载
评论 #27140187 未加载
评论 #27140125 未加载
laurent123456about 4 years ago
(2013)