I want to create a simple web server and check the operation of my application. (I want something like DummyServer)
HowTo
There seemed to be various ways to do it, but python seems to be quick, so I adopted python (Quick => linux comes standard)
Various = nc command, php, ruby, etc. are also possible.
(It can be anywhere, but I tried it with tmp for the time being)
cd /tmp
(Since I want to access cgi this time, create the following dir (cgi by default)-It seems to be useless unless it is named bin or htbin))
mkdir cgi-bin
(Try to place a script)
vi hoge.py
The contents are ↓↓↓
cat hoge.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
hoge="Welcome to one liner."
print """Content-Type: text/html
<html>
<body>
<h2>{0}</h2>
</body>
</html>
""".format(hoge)
$ chmod 655 hoge.py
$ sudo python -m CGIHTTPServer 1234
Serving HTTP on 0.0.0.0 port 1234 ...
$ curl localhost:1234/cgi-bin/hoge.py
<html>
<body>
<h2>Welcome to one liner.</h2>
</body>
</html>
Access log is also available
$ sudo python -m CGIHTTPServer 1234
Serving HTTP on 0.0.0.0 port 1234 ...
localhost - - [03/Dec/2014 19:06:01] "GET / HTTP/1.1" 200 -
localhost - - [03/Dec/2014 19:06:06] "GET /cgi-bin/hoge.py HTTP/1.1" 200 -
Isn't it really easy! ?? It is troublesome to set up a file server in-house, I wrote it at the beginning, but for the time being, how to use it like a Dummy Server (stub), if you want to move something, it is quite Isn't it easy to use?
Recommended Posts