Zend Framework не будет работать для URL-адресов с завершающим косой чертой – как настроить nginx правильно переписать URL-адреса?

Я настраиваю server nginx для использования с Zend Framework. По большей части это работает. Однако, если в конце URL-адреса есть конечная косая черта, например http://localhost/test/ vs http://localhost/test , URL-адрес с завершающей косой чертой не будет работать. Это неожиданно и несчастливо. Я хочу, чтобы он работал для обоих URL.

Что я должен сделать, чтобы решить эту проблему? Моя configuration nginx:

 server { listen 80; server_name mywebsite.com; root /var/www/site/public; location / { rewrite ^/(.*)/$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param APPLICATION_ENV development; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; } } имя_serverа mywebsite.com; server { listen 80; server_name mywebsite.com; root /var/www/site/public; location / { rewrite ^/(.*)/$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param APPLICATION_ENV development; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; } } root / var / www / site / public; server { listen 80; server_name mywebsite.com; root /var/www/site/public; location / { rewrite ^/(.*)/$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param APPLICATION_ENV development; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; } } переписать ^ / (. *) / $ / $ 1; server { listen 80; server_name mywebsite.com; root /var/www/site/public; location / { rewrite ^/(.*)/$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param APPLICATION_ENV development; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; } } fastcgi_param Разработка APPLICATION_ENV; server { listen 80; server_name mywebsite.com; root /var/www/site/public; location / { rewrite ^/(.*)/$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param APPLICATION_ENV development; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; } } fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; server { listen 80; server_name mywebsite.com; root /var/www/site/public; location / { rewrite ^/(.*)/$ /$1; include /etc/nginx/fastcgi_params; fastcgi_param APPLICATION_ENV development; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/site/public/index.php; } } 

Как вы можете viewеть, я попытался добавить условие перезаписи, но, похоже, это не имеет никакого значения.

Вот пара fileов конфигурации, которые я использую для приложений Zend Framework. Во-первых, php.conf , который я разделяю между проектами на моей рабочей станции разработки. Я держу это в directoryе выше моего directoryа sites прямо в корне конфигурации nginx (например, /usr/local/etc/nginx/php.conf ):

 fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } # это позволит Nginx перехватывать коды ошибок 4xx / 5xx fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } # Nginx будет только перехватывать, если определены правила страницы ошибки fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } # - Это лучше помещается в блок http {} по умолчанию fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } # - так что в случае WordPress вы можете отkeyить его fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } # - в serverном блоке этого виртуального хоста fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } fastcgi_param Разработка APPLICATION_ENV; fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } fastcgi_param SERVER_SOFTWARE nginx; fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- so that in the case of wordpress, you can turn it off specifically # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param APPLICATION_ENV development; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; fastcgi_read_timeout 60; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; } 

И затем блок server который использует это:

 server { listen 80; server_name local.example.com; root /var/www/example/public; location / { index index.php; try_files $uri $uri/ /index.php$is_args$args; } include php.conf; } имя_serverа local.example.com; server { listen 80; server_name local.example.com; root /var/www/example/public; location / { index index.php; try_files $uri $uri/ /index.php$is_args$args; } include php.conf; } root / var / www / example / public; server { listen 80; server_name local.example.com; root /var/www/example/public; location / { index index.php; try_files $uri $uri/ /index.php$is_args$args; } include php.conf; } 

В вашем случае, я думаю, что бит keyа – try_files $uri $uri/ /index.php$is_args$args; , где мы просто передаем URL-адрес и строку requestа опцию index.php , и пусть это делает синтаксический анализ.

  • Я получаю 500 ошибок на http: // localhost / zftutorial / public
  • Рекомендации по отладке Apache с ошибками сегментации PHP
  • procmail не выполняет скрипт php
  • Как развернуть два приложения для работы с основами zend в apache2, как в tomcat
  • PHP фатальная ошибка Zend при загрузке websiteа на website
  • Фатальная ошибка Weird Postfix
  • Mod_pagespeed с Zend Framework дает 404
  • Прокси Nginx не передает URL-адрес в структуре controllerа / действия для Apache2
  • Настройка Zend Framework на CentOS - Невозможно разместить папку Zend
  • Как исправить ошибку Apache «клиент, отказавшийся от конфигурации serverа»?
  • Postfix / OpenDKIM не подписывает PHP отправленные письма
  • Давайте будем гением компьютера.