针对http:(这个不设置,默认就是404)
- 设置返回 500 或者404
server {
listen 80 default;
server_name _;
return 404;
}
- 设置跳转到自己域名首页
server {
listen 80 default;
server_name _;
rewrite ^(.*) http://www.aaaa.cn permanent;
}
针对https:
可以自己随便生成一个证书(使用以下命令):
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./default.key -out ./default.crt
修改nginx配置:
server {
listen 443 ssl;
server_name _;
ssl_certificate /credential/default/default.crt;
ssl_certificate_key /credential/default/default.key;
return 404;
}
80 与 443 合并
server {
listen 80 default_server;
listen 443 ssl;
server_name _;
ssl_certificate /credential/default/default.crt;
ssl_certificate_key /credential/default/default.key;
return 404;
}
附加:
- 针对某一个域名https访问拦截:
server {
listen 443;
server_name www.****.com;
ssl_certificate /**/.pem;
ssl_certificate_key /**/.key;
return 404;
}