小辉网络社区致力于优质软件,活动线报,游戏辅助,绿色工具等资源共享,好货不私藏!

nginx防止恶意域名解析与反代80与443端口完整版

小辉工作室 其他技术教程

1、80端口防止反代比较容易,在nginx上加入如下配置即可。
server {
    listen       80  default_server;
    return       444;
}
2、443端口防范配置则需要配置ssl证书,否则所有https请求都会失败,下面是颁发自签名证书和配置过程。
(1)首先确保机器上安装了openssl和openssl-devel,没有的话执行如下指令安装:
yum install openssl
yum install openssl-devel
(2)生成证书
#首先,进入你想创建证书和私钥的目录,例如:
cd /home/certs/
#创建服务器私钥,命令会让你输入一个口令:
openssl genrsa -des3 -out server.key 2048
#创建签名请求的证书,最后两步密码留空(CSR):
openssl req -new -key server.key -out server.csr
#在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
#最后标记证书使用上述私钥和CSR:
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
3、配置Nginx,让其包含新标记的证书和私钥,实现https防止反代或者恶意解析。
server {
    listen 80 default;
    listen 443 ssl;
 
    ssl_certificate      /home/certs/server.crt;
    ssl_certificate_key  /home/certs/server.key;
 
    return 444;
}
4、通用证书
server.crt
-----BEGIN CERTIFICATE-----
MIIDADCCAegCCQD1QN1qSj8kbjANBgkqhkiG9w0BAQsFADBCMQswCQYDVQQGEwJD
TjEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBh
bnkgTHRkMB4XDTE5MTEyOTAxNTgyOFoXDTI5MTEyNjAxNTgyOFowQjELMAkGA1UE
BhMCQ04xFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBD
b21wYW55IEx0ZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANxdTeQg
CZU41f1DMn5LA+Wq9JhxfeZwUcOiz7VxfOMwkskpOqc28SjUdRl+fDuwmk7rJnvM
jmB3rZLKc6vw9cR0/fjMaT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cK9mW9PgtG
ZWRiSF0M+daAB4XElaMJ+1lhJFSVQKaNTW/U7i/YJa0slVh456+3hgBm0CdTOi3j
aVMjnJchKedL2C6yP1YJTc/VEeoxnpkSym5NgnSPSeiNW5bhn1gN
-----END RSA PRIVATE KEY-----

温馨提示:如有转载或引用以上内容请将本文链接作为出处标注!百度已收录

免责声明:本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。侵删请致信E-mail:431228450@qq.com

标签 暂无标签
资源分享
评论列表