I have a domain
https://www.example.com
and external ip address of my server
xxx.xxx.xxx.xxx
I am able to access my domain and ip address which will display the same page of my website
the "ONLY" code in my httpd-vhosts.conf are these:
<virtualhost *:443>
ServerAdmin webmaster@example.com
DocumentRoot "/mydir/"
ServerName www.example.com
ServerAlias www.example.com
ErrorLog "logs/example.com-error.log"
CustomLog "logs/example.com-access.log" common
SSLEngine on
SSLCertificateFile "etc/ssl.crt/example.crt"
SSLCertificateKeyFile "etc/ssl.key/example.key"
</virtualhost>
Now, I want to remove the access to everyone using my external ip address. I want to force visitors using my domain name instead of my external ip. It's all because my website have cloudflare dns and I don't want anyone to access my ip directly.
How to disable direct external ip access ?
Should I disabled all of it ports ?
TLDR: You can't.
The clients will always connect to the server using the IP address. The domain name is translated to the corresponding IP address by a DNS or a hosts file in the client's operating system. You could use a network sniffer like Wireshark to see that all IP packets use IP addresses. Only the HTTP/S content has additional host information like domain name. But routing is done with IP only.
I have solved the issues by modifying httpd-vhosts.conf to
<virtualhost *:443>
ServerAdmin webmaster@example.com
DocumentRoot "/mydir/"
ServerName www.example.com
ServerAlias www.example.com
ErrorLog "logs/example.com-error.log"
CustomLog "logs/example.com-access.log" common
SSLEngine on
SSLCertificateFile "etc/ssl.crt/example.crt"
SSLCertificateKeyFile "etc/ssl.key/example.key"
</virtualhost>
<virtualhost *:80>
ServerName localhost
Redirect 403 /
UseCanonicalName Off
UserDir disabled
</VirtualHost>
<virtualhost *:80>
ServerName xxx.xxx.xxx.xxx
Redirect 403 /
UseCanonicalName Off
UserDir disabled
</VirtualHost>
<virtualhost *:443>
ServerName localhost
Redirect 403 /
UseCanonicalName Off
UserDir disabled
</VirtualHost>
<virtualhost *:443>
ServerName xxx.xxx.xxx.xxx
Redirect 403 /
UseCanonicalName Off
UserDir disabled
</VirtualHost>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.