基础教程

关于EvoCMS的nginx 和 页面seo缓存配置

缓存 nginx

由于 EvoCMS 不需要数据库,因此使用起来非常方便,无需担心 EvoCMS 安装和任何其他重要数据源之间出现问题。如果出现问题,通常可以非常轻松地恢复。

页面编辑

EvoCMS中的页面采用Markdown语法编写。Markdown 是一种纯文本格式语法,计算机可以轻松解析并转换为 HTML。它使用基本的文本符号来表示呈现方式(例如粗体、斜体、标题、列表等),因此无需了解 HTML 的复杂性即可轻松编写。Markdown 的优点包括错误率低、可读性强、易于学习和使用等。

示例 nginx.conf

    user www-data;
    worker_processes auto;
    worker_rlimit_nofile 8192; # should be bigger than worker_connections
    pid /run/nginx.pid;

    events {
        use epoll;
        worker_connections 8000;
        multi_accept on;
    }

    http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;

        keepalive_timeout 30; # longer values are better for each ssl client, but take up a worker connection longer
        types_hash_max_size 2048;
        server_tokens off;

        # maximum file upload size
        # update 'upload_max_filesize' & 'post_max_size' in /etc/php/fpm/php.ini accordingly
        client_max_body_size 32m;
        # client_body_timeout 60s; # increase for very long file uploads

        # set default index file (can be overwritten for each site individually)
        index index.html;

        # load MIME types
        include mime.types; # get this file from https://github.com/h5bp/server-configs-nginx
        default_type application/octet-stream; # set default MIME type

        # logging
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        # turn on gzip compression
        gzip on;
        gzip_disable "msie6";
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 5;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_min_length 256;
        gzip_types
            application/atom+xml
            application/javascript
            application/json
            application/ld+json
            application/manifest+json
            application/rss+xml
            application/vnd.geo+json
            application/vnd.ms-fontobject
            application/x-font-ttf
            application/x-web-app-manifest+json
            application/xhtml+xml
            application/xml
            font/opentype
            image/bmp
            image/svg+xml
            image/x-icon
            text/cache-manifest
            text/css
            text/javascript
            text/plain
            text/vcard
            text/vnd.rim.location.xloc
            text/vtt
            text/x-component
            text/x-cross-domain-policy;

        # disable content type sniffing for more security
        add_header "X-Content-Type-Options" "nosniff";

        # force the latest IE version
        add_header "X-UA-Compatible" "IE=Edge";

        # enable anti-cross-site scripting filter built into IE 8+
        add_header "X-XSS-Protection" "1; mode=block";

        # include virtual host configs
        include sites-enabled/*;
    }

修复 httpoxy 漏洞

httpoxy 是一组影响在 CGI 或类似 CGI 环境中运行的应用程序代码的漏洞。

为了保护您的网站免受此漏洞的侵害,您应该阻止Proxy标头。这可以通过在配置中添加 FastCGI 参数来实现。只需打开文件/etc/nginx/fastcgi.conf并在末尾添加以下行:

  • fastcgi_param HTTP_PROXY "";

使用 SSL(使用现有证书)

如果您想使用现有的 SSL 证书来加密您的网站流量,本节提供了修改 Nginx 配置的必要步骤。

    # set the paths to your cert and key files here
    ssl_certificate /etc/ssl/certs/example.com.crt;
    ssl_certificate_key /etc/ssl/private/example.com.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DH        E-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:EC        DHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE        -DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SH        A:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
    ssl_prefer_server_ciphers on;

    ssl_session_cache shared:SSL:10m; # a 1mb cache can hold about 4000 sessions, so we can hold 40000 sessions
    ssl_session_timeout 24h;

    # Use a higher keepalive timeout to reduce the need for repeated handshakes
    keepalive_timeout 300s; # up from 75 secs default

    # submit domain for preloading in browsers at: https://hstspreload.appspot.com
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload;";

    # OCSP stapling
    # nginx will poll the CA for signed OCSP responses, and send them to clients so clients don't make their own OCSP calls.
    # see https://sslmate.com/blog/post/ocsp_stapling_in_apache_and_nginx on how to create the chain+root
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/ssl/certs/example.com.chain+root.crt;
    resolver 198.51.100.1 198.51.100.2 203.0.113.66 203.0.113.67 valid=60s;
    resolver_timeout 2s;

将未加密的 HTTP 请求重定向到 HTTPS,这意味着server重定向到监听端口 443 并包括您的块ssl.conf(将“example.com”替换为您的域/IP)。您还可以将其更改为从非 www 重定向到您的域的 www 版本。

EvoCMS站点

    # redirect http to non-www https
    server {
        listen [::]:80;
        listen 80;
        server_name example.com www.example.com;

        return 302 https://example.com$request_uri;
    }

    # redirect www https to non-www https
    server {
        listen [::]:443 ssl;
        listen 443 ssl;
        server_name www.example.com;

        # add ssl cert & options
        include ssl.conf;

        return 302 https://example.com$request_uri;
    }

    # serve website
    server {
        listen [::]:443 ssl;
        listen 443 ssl;
        server_name example.com;

        # add ssl cert & options
        include ssl.conf;

        root /var/www/example.com;

        index index.html index.php;

        # ...
        # the rest of this server block (location directives) is identical to the one from the shipped config
    }

资产的 Nginx 缓存标头

还建议在生产中启用这些。配置文件中的这些添加项将处理它们。'expires' 定义缓存的过期时间,在本例中为 30 天。请参阅此处有关 nginx 的 http 标头的完整文档 http://nginx.org/en/docs/http/ngx_http_headers_module.html。

    location ~* ^/forms-basic-captcha-image.jpg$ {
                    try_files $uri $uri/ /index.php$is_args$args;
            }

            location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                    expires 30d;
                    add_header Vary Accept-Encoding;
                    log_not_found off;
            }

            location ~* ^.+\.(?:css|cur|js|jpe?g|gif|htc|ico|png|html|xml|otf|ttf|eot|woff|woff2|svg)$ {
                    access_log off;
                    expires 30d;
                    add_header Cache-Control public;

    ## No need to bleed constant updates. Send the all shebang in one
    ## fell swoop.
                    tcp_nodelay off;

    ## Set the OS file cache.
                    open_file_cache max=3000 inactive=120s;
                    open_file_cache_valid 45s;
                    open_file_cache_min_uses 2;
                    open_file_cache_errors off;
            }

上一篇 下一篇