An open source secure web server that supports HTTP and HTTPS out of the box.
MVDServer runs in any operating system (Linux, Window or macOS) and does not require complex configurations.
You can integrate MVDServer in your own Java code as a library or use it from the command line to serve your web site.
Get the source code from GitHub and
use the jar files included in lib
folder in your Java project.
Follow these steps to launch MVDServer with its default configuration:
.\server.bat
or ./server.sh
On success, MVDServer will create a folder named www
with a default
index.html
page. You should see this in your browser:
To stop the server, visit this link: http://localhost:8080/stop?key=halt
Your browser will tell you that it can't connect and the terminal used to start MVDServer will notify you that the program stopped.
By default, MVDServer runs with these settings:
www
subfolderhalt
To customize MVDServer, edit the provided config.json
file or create a new one with the
same fields. Default configuration looks like this:
{ "hostName": "mysite.com", "httpPort": 8080, "httpsPort": 8443, "keystore": "", "password": "", "webDir": "www", "stopWord": "halt" }
Parameter | Description |
---|---|
hostName |
The domain name of the server. Required for HTTP/1.1 and used for redirecting to HTTPS. |
httpPort |
Port where the HTTP server listens to requests. Default is 8080 . |
httpsPort |
Port where the HTTPS server listens to requests. Default is 8443 . |
keystore |
Location of the Java keystore that contains the certificates used with the HTTPS server. |
password |
Password for the Java keystore that contains the certificates |
webDir |
Directory containing the content to serve. Default is www |
stopWord |
Code used for stopping the server using a browser. Default is halt . |
To use your own configuration file, simply run the server like this:
sh server.sh -config myConfig.json
or
.\server.bat -config myConfig.json
The HTTPS server is automatically enabled when the configuration file has a valid Keystore location and password.
You can use MVDServer binaries to create and manage a keystore. see the TLS/SSL Certificates tutorial for more details.
The standard port for HTTP protocol is 80
and the port for HTTPS is 443
.
MVDServer uses other ports by default because most operating systems will not let an unprivileged
user or application work with ports 80 and 443.
When using MVDServer on Linux, you can redirect the requests from standard ports to the ports used by
MVDServer using iptables
as root
like this:
iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 iptables -t nat -I PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443
To permanently redirect a moved page to its new location, add a JSON file named
redirects.json
to the root of your web site. Add an entry for each moved page using the old relative address as key
and the new absolute address as value. A redirected entry should look like this:
{ "/tools.html": "https://mvdsoftware.com/tools/index.html" }