微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

作为客户端的MVC的Nginxconfiguration

有人能发光吗? 这是问题:我需要在运行Nginx的服务器上创build一个站点。 我没有这台服务器的经验,所以我一直在坚持我的鼻子。 我想省略index.PHP,所以

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

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

然后我想提取/ welcome / index,这样我就可以在MVC应用程序中启动并使用它。 我一直在环顾四周,但我迷失在可能做自己的configuration的人的俱乐部。

我的问题是,如果我可以影响作为客户端的服务器响应,就像通过htaccess文件完成Apache一样,还是需要牵涉托pipe服务器的提供者? 我已经要求改变这个服务器,但我得到的支持不是很有帮助。

我能够在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; }

然后你从index.PHP中用$_GET['uri']访问URI。 你应该看看Nginx的try_files文档。

或者,如果你想通过$_SERVER['REQUEST_URI']来访问它,像这样做:

location / { try_files $uri $uri/ /index.PHP?$args; }

编辑:

有几件事只是看你的服务器conf:

您已经在http块中包含了mime.types,所以不需要再在server块中包含它们

移动root html;可能是一个好主意root html; 并index index.PHP...到你的server块

肯定读过这些示例配置(在评论中解释的一切),非常好的方式开始获得Nginx conf的挂钩

Nginx的网站有一些非常好的资源

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐