Конфигурация для nginx+php-fpm
Posted: Wed Sep 18, 2019 12:02 pm
Доброго времени суток, помогите собрать конфигурацию для статичного сайта.
Необходимо по мимо того, что убирать .html в конце, но и добавлять "/"
Чтобы в результате получилось. при открытии site.ru/online.html открылся site.ru/online/
Как убрать расширение .html я разобрался, а как добавить "/" в конце. А то выдает в 404 ошибку, какие условия я бы не писал.
Необходимо по мимо того, что убирать .html в конце, но и добавлять "/"
Чтобы в результате получилось. при открытии site.ru/online.html открылся site.ru/online/
Как убрать расширение .html я разобрался, а как добавить "/" в конце. А то выдает в 404 ошибку, какие условия я бы не писал.
Code: Select all
server {
listen %ip%:%web_ssl_port% ssl http2;
server_name %domain_idn% %alias_idn%;
root %sdocroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
ssl on;
ssl_certificate %ssl_pem%;
ssl_certificate_key %ssl_key%;
location / {
#убираю .html в конц
if ($request_uri ~ ^/(.*)\.html$) {
return 302 /$1;
}
try_files $uri $uri.html $uri/ =404;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass %backend_lsnr%;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias %home%/%user%/web/%domain%/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
location /vstats/ {
alias %home%/%user%/web/%domain%/stats/;
include %home%/%user%/conf/web/%domain%.auth*;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
pagespeed On;
pagespeed RewriteLevel CoreFilters;
# HTTPS Support
pagespeed FetchHttps enable,allow_self_signed;
#pagespeed EnableFilters lazyload_images,collapse_whitespace,insert_dns_prefetch,dedup_inlined_images,defer_javascript,pedantic,trim_urls,sprite_images,extend_cache_pdfs,remove_comments,resize_mobile_images,inline_preview_images,insert_image_dimensions,convert_to_webp_lossless,local_storage_cache,inline_google_font_css,prioritize_critical_css,rewrite_style_attributes,move_css_to_head,move_css_above_scripts,outline_javascript,outline_css,combine_heads;
pagespeed EnableFilters lazyload_images,combine_css,extend_cache,rewrite_images;
pagespeed EnableFilters rewrite_css,rewrite_javascript;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
include %home%/%user%/conf/web/snginx.%domain%.conf*;
}