Nginx的常用配置

www跳转到主域名

server {
    listen 80;
    server_name www.tool.lu;

    access_log off;
    error_log off;

    return 301 http://tool.lu$request_uri;
}

http跳转到https

server {
    listen      80;
    server_name tool.lu;
    return 301 https://tool.lu$request_uri;
}

fastcgi

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

cdn

server {
    listen 80;
    server_name s1.tool.lu s2.tool.lu s3.tool.lu s4.tool.lu;

    root /data/html/tool.lu/static;
    index index.html;

    access_log off;
    error_log off;

    location / {
        concat on;
        concat_types text/css application/javascript;
        # 解决js语句不以分号结尾的第三方库
        concat_delimiter "\n\n";
        concat_max_files 20;

        expires 7d;
    }
}

参考

  1. Pitfalls - Nginx Community

标签: none

添加新评论