学习nginx配置

server {
    listen  80;
    server_name www.abc.com;
    rewrite ^(.*)$  https://$host$1 permanent;
}
server {
    listen       443;
    server_name  www.abc.com;
    root   html/www;
    index  index.php index.html index.htm;
 
    #https证书
    ssl on;
    ssl_certificate /application/nginx/conf/key/server.crt;
    ssl_certificate_key /application/nginx/conf/key/server.key;
 
    #访问日志
    access_log  logs/access_www.log  main;
 
    #隐藏版本号
    server_tokens on;
 
    ##防盗链
    #location ~* .*\.(jpg|gif|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {      #小括号中不能包含要跳转的图片结尾格式.png,-->否则会进入死循环跳转
    #    valid_referers none blocked *.abc.com abc.com www.abc.com;
    #    if ($invalid_referer) {
    #       #return 403;
    #       rewrite ^/  https://www.abc.com/fangdaolian.png;
    #    }
    #}
 
    #客户端对静态内容缓存
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        expires 30y;
        root html/www;
    }
    location ~ .*\.(js|css)?$ {
        expires 30d;
        root html/www;
    }
 
    #php解析
    location ~ .*\.(php|php5)?$ {
        root html/www;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
 
        #FastCGI 相关参数调优
        #fastcgi_cache ngx_fcgi_cache;
        fastcgi_cache_valid 200 302 1h;
        fastcgi_cache_valid 301 1d;
        fastcgi_cache_valid any 1m;
        fastcgi_cache_min_uses 1;
        fastcgi_cache_use_stale error timeout invalid_header http_500;
        fastcgi_cache_key http://$host$request_uri;
    }
 
    #错误页面优化显示 注意将下面两个图片上传至服务器中
    error_page 500 501 502 503 504 http://www.abc.com/error2.jpg;
    error_page 400 403 404 405 408 410 412 413 414 415 http://www.abc.com/error1.jpg;
}

发布了543 篇原创文章 · 获赞 32 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/weixin_36691991/article/details/105067692
今日推荐