在Nginx中为Jekyll/Octopress/pelican配置静态网站

时间:2019-08-20 17:58:08  来源:igfitidea点击:

修改Nginx配置文件:

server {

    ## Give Domain name
    server_name example.com www.example.com;

    ## Define custom path for Nginx site log
    access_log /var/log/nginx/example.com-access.log;
    error_log /var/log/nginx/example.com-error.log;

    ## Give absolute path of Web root where your website files/dir are saved
    root /usr/local/nginx/html/examplecom_octopress;

    ## Define the index file
    index index.html;
    autoindex off;

    ## Setting Compression
  
    gzip on;
    gzip_disable "msie6";
    gzip_min_length 1100;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ## Define 404 pages URL
    location / {
     try_files $uri $uri/ =404; 

   }

    # Disable favicon.ico logging
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Allow robots and disable logging
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }


    # Disable static content logging and set cache time to max
    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 365d;
        log_not_found off;
    }

    # Deny access to htaccess and htpasswd files
    location ~ /.ht {
        deny  all;
    }
}

运行命令“nginx-t”,检查配置文件中是否有任何错误

重新启动Nginx服务。

在CentOS 7/RHEL 7上

systemctl restart nginx

在CentOS 5,6/RHEL 5,6上

service nginx restart

在Debian/Ubuntu上

sudo service nginx restart

或者

sudo /etc/init.d/nginx restart