我所有的链接都重定向到根目录,在那里我提供文件"index.php“。
这是我的nginx配置:/etc/nginx/sites available/myproject.local
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不允许“。
如果我添加了一个带有"location ~{ ... }“的规则,那么我就可以发布到"http://myproject.local”。但现在是"http://myproject.local/something“不起作用了。
如何在不中断其他路由的情况下,从根("/")提供"index.php“服务?
发布于 2019-02-01 20:44:32
到这一行:
位置~ .php$
我附加了|/$:
位置~ .php$|/$
以便它还可以接受空查询。
现在我可以使用post请求"myproject.local","myproject.local/index.php",""myproject.local/someroute“。
发布于 2019-02-01 11:00:51
消息"405不允许“的原因之一是nginx不能在POST-request上提供静态内容。你能展示更详细的配置吗?
https://stackoverflow.com/questions/54470895
复制相似问题