宝塔nginx的配置实例
# evocms.org默认nginx伪静态配置
index index.php index.html;
autoindex off;
location ~* /(\.git|cache|bin|logs|backups?|tests)/.*$ {
return 403;
}
location ~* /(system|vendor)/.*\.(txt|xml|md|html|htm|shtml|shtm|json|yaml|yml|php|php2|php3|php4|php5|phar|phtml|pl|py|cgi|twig|sh|bat)$ { return 403; }
location ~* /user/.*\.(txt|md|json|yaml|yml|php|php2|php3|php4|php5|phar|phtml|pl|py|cgi|twig|sh|bat)$ { return 403; }
location ~ /\.ht { deny all; }
rewrite ^/sitemap$ /sitemap.xml permanent;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffer_size 32k;
fastcgi_buffers 16 16k;
fastcgi_busy_buffers_size 64k;
fastcgi_temp_file_write_size 64k;
}
location ~* \.(?:sh|pl|py|exe)$ {
deny all;
}
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff|woff2|svg|ttf|otf|eot|webp)$ {
expires 60d;
add_header Vary Accept-Encoding;
add_header Cache-Control public;
etag on;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
types_hash_max_size 2048;
include mime.types;
default_type application/octet-stream;
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/avif
image/webp
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;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header "X-Content-Type-Options" "nosniff";
add_header "X-UA-Compatible" "IE=Edge";
add_header "X-XSS-Protection" "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
include sites-enabled/*;