nginx.conf ниже работает, кроме домашней страницы, которую localdomain перенаправляет на LOCALDOMAIN / индекс /.
Это конфинг перенаправляет .php в / конечный слеш, и phpless url на конечный слеш.
Очевидно, что-то не так, и все возможные изменения, которые я попробовал, не сработали. Если я удалю из сервер контекст rewrite ^(.*).php$ $1/ permanent;
затем localdomain отображается нормально без / index / , но я потеря перенаправления .php в конце. Я полностью сбит с толку, и любое решение будет с благодарностью.
user nginx;
worker_processes 4;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
port_in_redirect off;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_bucket_size 64;
client_max_body_size 100m;
server_names_hash_bucket_size 128;
include mime.types;
default_type application/octet-stream;
index index.php index.html index.htm;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#=====================Basic Compression=====================
gzip on;
#gzip_disable "msie6";
#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/javascript text/xml application/xml application/xml+rss text/javascript;
#gzip_static on;
server {
listen 80;
server_name 192.168.10.2;
root /home/html_public;
index index.php index.html;
charset UTF-8;
rewrite ^(.*).php$ $1/ permanent;
location @extensionless-php {
rewrite ^(.*)/$ $1.php last;
rewrite ^(.*)$ $1/ permanent;
}
location / {
try_files $uri $uri/ @extensionless-php;
}
#error_page 404 /404.php;
# permanent server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location /phpMyAdmin {
root /usr/share/;
location ~ ^/phpMyAdmin/(.+\.php)$ {
root /usr/share/;
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpMyAdmin/(.+\ (jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpmyadmin {
rewrite ^/* /phpMyAdmin last;
}
}
}
[Обновленная версия]
user nginx;
worker_processes 4;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
port_in_redirect off;
server_tokens off;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_bucket_size 64;
client_max_body_size 100m;
server_names_hash_bucket_size 128;
include mime.types;
default_type application/octet-stream;
index index.php index.html index.htm;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#=====================Basic Compression=====================
gzip on;
#gzip_disable "msie6";
#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/javascript text/xml application/xml application/xml+rss text/javascript;
#gzip_static on;
server {
listen 80;
server_name 192.168.10.2;
root /home/html_public;
charset UTF-8;
#access_log logs/host.access.log main;
rewrite ^(.*).php$ $1/ permanent;
location @extensionless-php {
rewrite ^(.*)/$ $1.php last;
return 301 http://$host$request_uri/;
}
location = / {
rewrite ^ /index/;
}
location / {
try_files $uri $uri/ @extensionless-php;
}
#error_page 404 /404.php;
# permanent server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
location /phpMyAdmin {
root /usr/share/;
location ~ ^/phpMyAdmin/(.+\.php)$ {
root /usr/share/;
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpmyadmin {
rewrite ^/* /phpMyAdmin last;
}
}
}
Задача ещё не решена.
Других решений пока нет …