重定向到 root,即使查询为空
redirecting to root, even if query is empty
我所有的链接都重定向到根目录,我在那里提供文件 "index.php"。
这是我的 nginx 配置:
/etc/nginx/sites-available/myproject.本地
server {
listen 80;
listen 444 ssl http2;
server_name .buildurlshortener.local;
root "/home/vagrant/codecourse/buildurlshortener/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/buildurlshortener.local-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/buildurlshortener.local.crt;
ssl_certificate_key /etc/nginx/ssl/buildurlshortener.local.key;
}
如果我向“http://myproject.local/something”发出 post 请求,它会起作用。
但是对根的 post 请求,即 http://myproject.local,不起作用。
我从 nginx 收到“405 Not Allowed”。
如果我添加一个规则"location ~ { ... }",那么我可以post到“http://myproject.local”。但现在是“http://myproject.local/something”不起作用。
如何在不破坏其他路由的情况下从根目录 ("/") 提供 "index.php" 服务?
消息“405 Not Allowed”的原因之一是 nginx 无法在 POST-请求上提供静态内容。你能更详细地显示配置吗?
到这一行:
位置 ~ .php$
我附加了 |/$
:
位置 ~ .php$|/$
这样它也可以接受空查询。
现在我可以使用 post 请求 "myproject.local", "myproject.local/index.php", ""myproject.local/someroute".
我所有的链接都重定向到根目录,我在那里提供文件 "index.php"。
这是我的 nginx 配置: /etc/nginx/sites-available/myproject.本地
server {
listen 80;
listen 444 ssl http2;
server_name .buildurlshortener.local;
root "/home/vagrant/codecourse/buildurlshortener/public";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/buildurlshortener.local-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/buildurlshortener.local.crt;
ssl_certificate_key /etc/nginx/ssl/buildurlshortener.local.key;
}
如果我向“http://myproject.local/something”发出 post 请求,它会起作用。
但是对根的 post 请求,即 http://myproject.local,不起作用。 我从 nginx 收到“405 Not Allowed”。
如果我添加一个规则"location ~ { ... }",那么我可以post到“http://myproject.local”。但现在是“http://myproject.local/something”不起作用。
如何在不破坏其他路由的情况下从根目录 ("/") 提供 "index.php" 服务?
消息“405 Not Allowed”的原因之一是 nginx 无法在 POST-请求上提供静态内容。你能更详细地显示配置吗?
到这一行:
位置 ~ .php$
我附加了 |/$
:
位置 ~ .php$|/$
这样它也可以接受空查询。
现在我可以使用 post 请求 "myproject.local", "myproject.local/index.php", ""myproject.local/someroute".