gpt4 book ai didi

model-view-controller - MVC 作为客户端的 Nginx 配置

转载 作者:行者123 更新时间:2023-12-04 00:15:09 25 4
gpt4 key购买 nike

有人能发光吗?
这就是问题所在:我需要在运行 Nginx 的服务器上创建一个站点。我对这台服务器没有经验,所以我一直对它嗤之以鼻。
我想省略 index.php,这样

http://www.mydomain.com/index.php/welcome/index

变成
http://www.mydomain.com/welcome/index

然后我想提取/welcome/index 以便我可以在 MVC 应用程序中开始并使用它。我一直在环顾四周,但我迷失在可能进行自己配置的人的俱乐部中。

我的问题是,我是否可以作为客户端影响服务器响应,就像通过 htaccess 文件使用 Apache 完成的那样,或者我是否需要让托管服务器的提供者参与进来?我已要求为此更改服务器,但我获得的支持并不是很有帮助。

我能够在 nginx.conf 文件中模拟所需的服务器响应。这告诉我这是可以做到的。
对于那些有兴趣的人。通过 $_SERVER['REQUEST_URI'] 读取 url 上的值。
worker_processes  1;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

sendfile on;

#keepalive_timeout 0;
keepalive_timeout 65;

server {
listen 80;
server_name localhost;

location / {
root html;
index index.php index.html index.htm;


try_files $uri $uri/ /index.php;

}

include mime.types;


# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


}

}

最佳答案

我这样做:

location / {
try_files $uri $uri/ /index.php?uri=$uri&$args;
}

然后您使用 $_GET['uri'] 访问 URI来自您的 index.php .你应该看看 nginx 的 try_files文档。

或者,如果您想通过 $_SERVER['REQUEST_URI'] 访问它像这样做:
location / {
try_files $uri $uri/ /index.php?$args;
}

编辑:

一些事情只是看看你的服务器配置:
  • 您已经在 http 中包含了 mime.types块,因此无需在 server 中再次包含它们。区块
  • 搬家可能是个好主意root html;index index.php...直到您的 server区块
  • 一定要通读these示例配置(在评论中解释了所有内容),这是开始掌握 nginx conf
  • 的好方法
  • Nginx website有一些非常好的资源
  • 关于model-view-controller - MVC 作为客户端的 Nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13227347/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com