一、主配置文件
二、web服务器与https配置
需要编译ngx_http_ssl_module模块
server {
listen 443;
#监听端口
server_name c.guanshizhai.online;
#虚拟主机名
add_header Cache-Control "max-age=800";
#设置缓存时间
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
if ($http_user_agent ~ "AhrefsBot|360Spider|^$" )
{
return 403;
}
#参考主配置文件介绍
#charset koi8-r;
gzip on;
gzip_comp_level 4;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/png image/jpeg image/gif;
gzip_min_length 1k;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6].";
#参考主配置文件介绍
ssl on;
#开启https
ssl_certificate /usr/local/nginx/sslkey/1_c.guanshizhai.online_bundle.crt;
ssl_certificate_key /usr/local/nginx/sslkey/2_c.guanshizhai.online.key;
#私钥和公钥配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#ssl协议版本
ssl_session_cache shared:SSL:1m;
#设置存储session参数的缓存的类型和大小。具体配置看文末的参考文章。
ssl_session_timeout 5m;
#session 失效时间。
ssl_ciphers HIGH:!aNULL:!MD5;
#加密套件
ssl_prefer_server_ciphers on;
#设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户端浏览器的加密套件。
location ~ /*\.(php|php5|asp)$ {
deny all;
}
#所有以php、php5、asp的url,都拒绝。
location / {
root /usr/local/project/blog/output/;
index guanshizhai.html index.htm;
}
#定义默认的html文件
}
三、http代理
主配置文件参考nginx.conf
upstream guanshizhaiproxy {
真实主机配置块
server 120.92.51.3;
#后端真实主机IP
}
server {
listen 80;
listen 443;
#监控端口
server_name c.guanshizhai.online;
#监听主机名
add_header Cache-Control "max-age=0";
#设置缓存时间
location / {
proxy_http_version 1.1;
#代理的http协议版本,默认1.0,推荐使用1.1,并且与keepalive一起使用
proxy_set_header Host $host;
#重新定义host头
proxy_set_header X-Real-IP $remote_addr;
#把remote_addr里面的ip赋值给X-Real-IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#把代理IP赋值给X-Forwarded-For
proxy_set_header Cookie $http_cookie;
#复制cookie
proxy_pass http://guanshizhaiproxy;
#跳转地址
add_header Cache-Control "max-age=0";
#设置不缓存
}
}
四、302配置
server {
listen 80;
server_name blog.guanshizhai.com;
rewrite ^/(.*) http://c.guanshizhai.online/$1 redirect;
access_log off;
charset utf-8;
#access_log off;
}
五、参考文章
1. ssl_prefer_server_ciphers
https://segmentfault.com/a/1190000002866627
2. ssl_session_cache说明
https://blog.csdn.net/zhxuewu/article/details/77976714
3. ssl_ciphers
https://blog.csdn.net/u011537073/article/details/53933249
4. http代理配置
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
X-Real-IP、X-Forwarded-For
https://blog.csdn.net/caoshuming_500/article/details/20952329