首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重定向到根目录,即使查询为空

问重定向到根目录,即使查询为空
EN

Stack Overflow用户
提问于 2019-02-01 07:43:05
回答 2查看 48关注 0票数 0

我所有的链接都重定向到根目录,在那里我提供文件"index.php“。

这是我的nginx配置:/etc/nginx/sites available/myproject.local

代码语言:javascript
复制
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“服务?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-01 20:44:32

到这一行:

位置~ .php$

我附加了|/$:

位置~ .php$|/$

以便它还可以接受空查询。

现在我可以使用post请求"myproject.local","myproject.local/index.php",""myproject.local/someroute“。

票数 0
EN

Stack Overflow用户

发布于 2019-02-01 11:00:51

消息"405不允许“的原因之一是nginx不能在POST-request上提供静态内容。你能展示更详细的配置吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54470895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档