Skip to content

Instantly share code, notes, and snippets.

@sudahiroshi
Last active April 17, 2018 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudahiroshi/8329895 to your computer and use it in GitHub Desktop.
Save sudahiroshi/8329895 to your computer and use it in GitHub Desktop.
ワンライナーWebサーバを集めてみた ref: https://qiita.com/sudahiroshi/items/e74d61d939f18779970d
$ python -m SimpleHTTPServer 3000
Serving HTTP on 0.0.0.0 port 3000 ...
$ light-server -s . --http2
light-server is listening at https://0.0.0.0:4000
serving static dir: .
$ light-server -s .
light-server is listening at http://0.0.0.0:4000
serving static dir: .
GET /index.html 200 29.438 ms - -
$ ruby -rsinatra -e 'set :public_folder, "./", get("/"){"Hello world"}'
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:4567, CTRL+C to stop
127.0.0.1 - - [09/Jan/2014 13:56:05] "GET / HTTP/1.1" 200 11 0.0025
$ serve
┌─────────────────────────────────────────────────┐
│ │
│ Serving! │
│ │
│ - Local: http://localhost:5000 │
│ - On Your Network: http://192.168.1.3:5000 │
│ │
│ Copied local address to clipboard! │
│ │
└─────────────────────────────────────────────────┘
$ ruby -run -e httpd . -p 8000
[2014-03-01 11:03:36] INFO WEBrick 1.3.1
[2014-03-01 11:03:36] INFO ruby 2.0.0 (2013-06-27) [universal.x86_64-darwin13]
[2014-03-01 11:03:36] INFO WEBrick::HTTPServer#start: pid=825 port=8000
localhost - - [01/Mar/2014:11:03:49 JST] "GET /test.html HTTP/1.1" 200 94937
- -> /test.html
$ ruby -rwebrick -rwebrick/https -e 'WEBrick::HTTPServer.new(:DocumentRoot => "./", :Port => 8000, :SSLEnable => true, :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.open("localhost.key").read), SSLCertificate: OpenSSL::X509::Certificate.new(File.open("localhost.crt").read), :SSLCertName => [["CN", WEBrick::Utils::getservername]] ).start'
[2018-04-18 03:30:53] INFO WEBrick 1.3.1
[2018-04-18 03:30:53] INFO ruby 2.3.1 (2016-04-26) [x86_64-darwin14]
[2018-04-18 03:30:53] INFO
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
c7:92:94:c6:4b:1f:75:65
Signature Algorithm: sha256WithRSAEncryption
Issuer: C=JP, ST=Some-State, O=Internet Widgits Pty Ltd
Validity
Not Before: Apr 17 18:23:43 2018 GMT
Not After : Apr 17 18:23:43 2019 GMT
Subject: C=JP, ST=Some-State, O=Internet Widgits Pty Ltd
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:c3:c7:93:ee:fb:00:4f:b1:b4:6a:8d:b8:13:7e:
b0:f9:7e:63:43:21:40:1c:c2:2e:ce:f4:fa:68:37:
03:8b:1b:e1:c3:de:3c:4e:23:d3:9b:b8:78:d3:47:
3c:78:1f:fb:97:43:d3:ec:6f:8d:56:ee:c1:5a:16:
a7:84:91:bf:c3:79:e2:d4:33:cd:f3:b5:7d:5b:55:
d2:ef:3f:f8:9d:fe:e1:28:04:24:2d:5a:ef:dd:cc:
10:ba:2e:d8:ed:65:61:5b:95:1a:11:5c:1a:c3:1d:
76:5f:b2:c8:05:66:88:e0:38:03:4b:fd:0a:51:2c:
9f:3e:ff:f0:40:66:02:ba:b5:14:d2:c9:09:3a:c0:
c3:40:6a:2f:6c:ed:6b:e1:72:f2:19:c2:41:7a:9c:
fb:83:81:ab:df:a1:3b:db:29:b1:4d:a6:89:43:28:
17:2a:ee:77:47:60:52:66:fa:08:e4:e5:ec:0e:cd:
33:1d:e9:86:81:c3:66:d3:40:63:62:f1:da:83:8a:
8a:e9:fd:c5:7b:11:13:d6:9a:74:ef:5b:aa:ac:19:
59:8d:a6:ae:22:95:c8:b5:5f:05:bd:09:5d:df:6c:
09:b0:9f:22:7f:81:ee:4f:42:5c:e9:4c:7e:0c:75:
1b:b3:14:4d:32:cf:86:28:0a:a5:d1:f5:64:b6:5f:
26:e1
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Subject Key Identifier:
A7:A1:32:FD:43:80:05:EC:F0:1B:41:0C:3B:0A:05:DE:46:F1:B5:32
X509v3 Authority Key Identifier:
keyid:A7:A1:32:FD:43:80:05:EC:F0:1B:41:0C:3B:0A:05:DE:46:F1:B5:32
DirName:/C=JP/ST=Some-State/O=Internet Widgits Pty Ltd
serial:C7:92:94:C6:4B:1F:75:65
X509v3 Basic Constraints:
CA:TRUE
Signature Algorithm: sha256WithRSAEncryption
2b:b0:86:47:9f:29:d0:2d:99:85:7f:52:fd:46:af:5a:ef:97:
de:98:da:ab:a6:97:4b:3a:16:06:52:ad:ec:9d:37:47:1d:af:
3d:59:11:43:ca:2e:24:77:88:d3:68:67:cb:53:72:d9:c2:d5:
a2:26:00:34:26:63:db:1b:86:63:4f:94:ac:20:ee:07:07:67:
ad:50:67:3a:fa:b8:0a:56:10:9f:e6:c2:80:df:6d:42:2e:cf:
91:ff:2e:de:02:5a:63:5c:45:0c:e7:8a:0c:a5:42:4d:09:1c:
1f:c1:28:6b:5e:2e:98:fd:65:d5:83:43:c4:2b:72:f4:61:ca:
d5:8a:65:4d:10:bd:6b:0a:ce:b5:ea:86:8e:cc:18:61:87:88:
b0:26:e0:42:22:75:e6:36:12:19:79:52:76:5c:94:f4:3b:7a:
1e:16:5d:ea:28:1b:a8:b3:f8:aa:49:05:c5:07:f8:5c:7f:99:
96:cf:f6:d5:71:8d:37:40:94:06:82:d0:d1:67:49:93:1c:29:
7f:85:18:12:83:4a:0c:95:08:8e:19:e6:07:4a:9e:a1:35:81:
a6:65:35:d9:ea:a0:cd:b8:6a:c8:f9:fe:0f:b5:1e:bd:df:48:
64:f1:bb:a4:b6:97:cc:75:fc:40:a5:4c:e9:6b:e4:9a:2f:a0:
36:d8:39:f8
[2018-04-18 03:30:53] INFO WEBrick::HTTPServer#start: pid=10166 port=8000
::1 - - [18/Apr/2018:03:30:55 JST] "GET / HTTP/1.1" 200 1996
- -> /
$ http-server -p 8000 -S -C localhost.crt -K localhost.key
Starting up http-server, serving ./public through https
Available on:
https://127.0.0.1:8000
https://192.168.1.3:8000
Hit CTRL-C to stop the server
$ while :; do { echo -e 'HTTP/1.1 200 OK\n\nhello'; } | nc -l 8000; done
$ http-server
Starting up http-server, serving ./public
Available on:
http:127.0.0.1:8080
http:192.168.0.1:8080 (←localhost以外でも待ち受けします)
Hit CTRL-C to stop the server
[Wed, 02 Dec 2015 04:10:35 GMT] "GET /" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"
$ mkdir cgi-bin
$ cd cgi-bin
$ cat > index.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
文字列(hello world.)を表示する
'''
print "Content-Type: text/plain"
print
print "hello world."
^D (←コントロール+Dを押してください)
$ chmod 755 index.py
$ cd ..
$ tree
.
└── cgi-bin
   └── index.py
$ cpan
(結構長いです.インストール先など,いくつか質問されるので適切に入力する.私は全て標準的な設定でよかったのでEnterを押しました.最後に起動スクリプトに環境変数を設定して良いか聞かれます.)
$ sudo cpan Task::Plack
(こちらも結構長いです.必要なモジュールなどをダウンロードします.待たされた後,標準的なインストールで良いか聞かれるので適切に答えてください.私はYを選択しました.また,最初にsudo無しで実行したらPermission Deniedと表示されたのでsudoを付けています.)
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
127.0.0.1 - - [09/Jan/2014 11:21:09] "GET / HTTP/1.1" 200 -
$ python -m SimpleHTTPServer 3000
Serving HTTP on 0.0.0.0 port 3000 ...
$ ruby -run -e httpd . -p 8000
[2014-03-01 11:03:36] INFO WEBrick 1.3.1
[2014-03-01 11:03:36] INFO ruby 2.0.0 (2013-06-27) [universal.x86_64-darwin13]
[2014-03-01 11:03:36] INFO WEBrick::HTTPServer#start: pid=825 port=8000
localhost - - [01/Mar/2014:11:03:49 JST] "GET /test.html HTTP/1.1" 200 94937
- -> /test.html
$ python -m http.server 8000
$ npm start
> web@1.0.0 start /home/suda
> http-server -p 8000
Starting up http-server, serving ./
Available on:
http:127.0.0.1:8000
http:172.16.11.3:8000
Hit CTRL-C to stop the server
$ npm start
> web@1.0.0 start /home/suda
> http-server -p 8000
Starting up http-server, serving ./public
Available on:
http:127.0.0.1:8000
http:192.168.0.1:8000
Hit CTRL-C to stop the server
$ npm start
> web@1.0.0 start /home/suda
> http-server -p 8000
Starting up http-server, serving ./public
Available on:
http:127.0.0.1:8000
http:192.168.0.1:8000
Hit CTRL-C to stop the server
$ npm start
> web@1.0.0 start /home/suda
> http-server -p 8000
Starting up http-server, serving ./public
Available on:
http:127.0.0.1:8000
http:192.168.0.1:8000
Hit CTRL-C to stop the server
$ ruby -rwebrick -e 'WEBrick::HTTPServer.new(:DocumentRoot => "./", :Port => 8000).start'
[2014-01-09 13:49:12] INFO WEBrick 1.3.1
[2014-01-09 13:49:12] INFO ruby 1.9.3 (2013-06-27) [x86_64-darwin12.4.0]
[2014-01-09 13:49:12] INFO WEBrick::HTTPServer#start: pid=9479 port=8000
localhost - - [09/Jan/2014:13:49:15 JST] "GET / HTTP/1.1" 200 2377
- -> /
$ npm start
> web@1.0.0 start /home/suda
> http-server -p 8000
Starting up http-server, serving ./public
Available on:
http:127.0.0.1:8000
http:192.168.0.1:8000
Hit CTRL-C to stop the server
$ ps aux | grep ruby
webrickのプロセス番号を調べて
$ kill -KILL プロセス番号
$ ruby -rsinatra -e 'set :public_folder, "./", get("/"){"Hello world"}'
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on localhost:4567, CTRL+C to stop
127.0.0.1 - - [09/Jan/2014 13:56:05] "GET / HTTP/1.1" 200 11 0.0025
$ ruby -rsinatra -e 'set :port, 8000; set :public_folder, "./", get("/"){"Hello world"}'
ruby -rsinatra -e 'set :port, 8000; set :public_folder, "./"; set :environment, :producntion; get("/"){"Hello world"}'
$ php -S localhost:8000
PHP 5.4.17 Development Server started at Thu Jan 9 17:35:44 2014
Listening on http://localhost:8000
Document root is /hoge
Press Ctrl-C to quit.
[Thu Jan 9 17:35:48 2014] ::1:59299 [404]: / - No such file or directory
$ php -S 0.0.0.0:8000
$ ./node_modules/.bin/http-server -p 8000
Starting up http-server, serving ./
Available on:
http:127.0.0.1:8000
http:192.168.0.1:8000
Hit CTRL-C to stop the server
$ npm install http-server
http-server@0.8.5 node_modules/http-server
├── opener@1.4.1
├── corser@2.0.0
├── colors@1.0.3
├── http-proxy@1.12.0 (eventemitter3@1.1.1, requires-port@0.0.1)
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── ecstatic@0.7.6 (url-join@0.0.1, he@0.5.0, mime@1.3.4, minimist@1.2.0)
├── union@0.4.4 (qs@2.3.3)
└── portfinder@0.4.0 (async@0.9.0, mkdirp@0.5.1)
$
$ light-server -s -w "**/*.js, index.html # npm run build # reload"
$ php -S localhost:8000
PHP 5.4.17 Development Server started at Thu Jan 9 17:35:44 2014
Listening on http://localhost:8000
Document root is /hoge
Press Ctrl-C to quit.
[Thu Jan 9 17:35:48 2014] ::1:59299 [404]: / - No such file or directory
$ cd public (←publicにcdしていても・・・)
$ $(npm bin)/http-server -p 8000 (←実行可能.※本来はこの行のみで実行)
Starting up http-server, serving ./
Available on:
http:127.0.0.1:8000
http:192.168.0.1:8000
Hit CTRL-C to stop the server
{
"name": "web",
"version": "1.0.0",
"description": "シンプルなWebサーバ",
"scripts": {
"start": "http-server -p 8000"
},
"author": "suda",
"license": "ISC",
"dependencies": {
"http-server": "^0.8.5"
}
}
$ npm install
npm WARN package.json web@1.0.0 No repository field.
npm WARN package.json web@1.0.0 No README data
http-server@0.8.5 node_modules/http-server
├── opener@1.4.1
├── corser@2.0.0
├── colors@1.0.3
├── http-proxy@1.12.0 (eventemitter3@1.1.1, requires-port@0.0.1)
├── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)
├── union@0.4.4 (qs@2.3.3)
├── portfinder@0.4.0 (async@0.9.0, mkdirp@0.5.1)
└── ecstatic@0.7.6 (url-join@0.0.1, he@0.5.0, mime@1.3.4, minimist@1.2.0)
$
$ plackup -MPlack::App::Directory -e 'Plack::App::Directory->new({root=>$ENV{PWD}})->to_app'
HTTP::Server::PSGI: Accepting connections at http://0:5000/
127.0.0.1 - - [02/Dec/2015:14:01:01 +0900] "GET / HTTP/1.1" 200 31580 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"
127.0.0.1 - - [02/Dec/2015:14:01:02 +0900] "GET /favicon.ico HTTP/1.1" 404 9 "http://localhost:5000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"
.
└── public
└── index.html
$ SERVE_USER=suda SERVE_PASSWORD=suda1234 serve --ah
th
┌─────────────────────────────────────────────────┐
│ │
│ Serving! │
│ │
│ - Local: http://localhost:5000 │
│ - On Your Network: http://192.168.1.3:5000 │
│ │
│ Copied local address to clipboard! │
│ │
└─────────────────────────────────────────────────┘
$ http-server -p 8000 -o
Starting up http-server, serving ./public
Available on:
http:127.0.0.1:8000
http:172.16.11.3:8000
Hit CTRL-C to stop the server
[Wed, 02 Dec 2015 05:10:59 GMT] "GET /" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"
[Wed, 02 Dec 2015 05:11:00 GMT] "GET /favicon.ico" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36"
[Wed, 02 Dec 2015 05:11:00 GMT] "GET /favicon.ico" Error (404): "Not found"
$ ps aux | grep ruby
webrickのプロセス番号を調べて
$ kill -KILL プロセス番号
$ ps aux | grep ruby
webrickのプロセス番号を調べて
$ kill -KILL プロセス番号
$ python -m CGIHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
127.0.0.1 - - [02/Dec/2015 12:53:38] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [02/Dec/2015 12:53:39] code 404, message File not found
127.0.0.1 - - [02/Dec/2015 12:53:39] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [02/Dec/2015 12:53:47] "GET /cgi-bin/index.py HTTP/1.1" 200 -
$ openssl req -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout localhost.key -out localhost.crt
Generating a 2048 bit RSA private key
.............................................................+++
..............................................................................................................................................................+++
writing new private key to 'localhost.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:
$ ls
localhost.crt localhost.key
$ while :; do { echo -e 'HTTP/1.1 200 OK\n\n'; cat index.html; } | nc -l 8000; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment