How to return status 301 on port 80 without webserver
Is there any way to implement HTTP redirect on port 80 if there's no web servers installed?
I want to protect my server from random access and redirect whoever hits port 80 or 443 there to the main websites. Right now it is setup to drop connection attempts on both ports.
I know, I could've created simple app that will listen port 80 and return http header with 301 status, but I'm curious if that's can be done kinda native?
11 Answer
You can use netcat as a very simple web server:
yes | xargs -i printf 'HTTP/1.0 301 Moved Permanently\nLocation: | sudo nc -k -l 80 5