如果您想了解使用nginx通过index.php路由请求的相关知识,那么本文是一篇不可错过的文章,我们将对nginx根据请求路径跳转进行全面详尽的解释,并且为您提供关于centos–如何使用nginx
如果您想了解使用nginx通过index.php路由请求的相关知识,那么本文是一篇不可错过的文章,我们将对nginx根据请求路径跳转进行全面详尽的解释,并且为您提供关于centos – 如何使用nginx通过HTTP发布git repo?、Laravel 5 nginx domain.com/index.php和domain.com/都可以使用.如何重定向/index.php?、nginx - index.php 能访问, index-test.php 能访问, indexa.php 就不能访问了, 为什么?、nginx - tengine+php-fpm,访问index.php正常,访问index.PHP却会吧php文件下载过来。的有价值的信息。
本文目录一览:- 使用nginx通过index.php路由请求(nginx根据请求路径跳转)
- centos – 如何使用nginx通过HTTP发布git repo?
- Laravel 5 nginx domain.com/index.php和domain.com/都可以使用.如何重定向/index.php?
- nginx - index.php 能访问, index-test.php 能访问, indexa.php 就不能访问了, 为什么?
- nginx - tengine+php-fpm,访问index.php正常,访问index.PHP却会吧php文件下载过来。
使用nginx通过index.php路由请求(nginx根据请求路径跳转)
我将我的服务器从Apache迁移到Nginx,并有这个非常简单的.htaccess规则:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.PHP [QSA,L]
它背后的想法是将每个请求都引导到前端控制器( index.PHP )。 我正在尝试与Nginx一样。 我使用了一个在线转换器来创build这个Nginx位置块:
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.PHP break; } }
但是当我把它添加到我的网站的configurationNginx只是吐出PHP文件的源代码作为下载。 作为参考,这里是整个configuration文件:
http://pastebin.com/tyKtM1iB
使用PHP和Apache路由URLpath
我知道PHP的作品,如果我删除位置块,并与<?PHP PHPinfo(); 它工作正常。
任何帮助,将不胜感激。
这是我如何将所有的东西路由到index.PHP,包括子目录请求,HTTP参数等。
location / { try_files $uri $uri/ /index.PHP?$args; #if doesn't exist,send it to index.PHP } location ~ .PHP$ { include fastcgi_params; fastcgi_intercept_errors on; # By all means use a different server for the fcgi processes if you need to fastcgi_pass 127.0.0.1:9000; }
所以例如,这些得到发送到index.PHP:
http://foo.bar/something/ http://foo.bar/something/?something=1
这些直接进入文件
http://foo.bar/someotherPHP.PHP http://img.zgserver.com/PHP/someimg.jpg
跳过正则表达式的结尾:
location / { index index.html index.PHP; if (!-e $request_filename) { rewrite ^.* /index.PHP break; fastcgi_pass 127.0.0.1:9001; } }
centos – 如何使用nginx通过HTTP发布git repo?
我在domain.fr上有一个CentOS 5服务器.我正在尝试设置子域,以便我可以将它与git:git.domain.fr一起使用
我的存储库位于/ home / git(例如/home/git/repos.git)
我已经安装了git-http-backend和Nginx.我已经设置了这样的存储库:
cd /home/git/repos.git && git --bare init
我已经设置了我的git.conf(包含在Nginx.conf中),如下所示.
但是,在我的客户端shell上,我收到致命错误“找不到存储库”:git clone http://git.domain.fr/repos.git
有谁知道我应该怎么做?看起来很简单,我感到沮丧,因为我确定它没什么.
server {
listen 80;
server_name git.domain.fr;
root /home/git;
location ~ /(/.*) {
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/bin/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL true;
fastcgi_param GIT_PROJECT_ROOT /home/git;
fastcgi_param PATH_INFO $1;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
}
解决方法:
我在一个标题为How to serve GIT through HTTP via NGINX with user/password?的SO Q& A中找到了这个片段.
http {
...
server {
listen 80;
server_name git.mydomain.com;
location ~ /git(/.*) {
# fcgiwrap is set up to listen on this host:port
fastcgi_pass localhost:9001;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
# export all repositories under GIT_PROJECT_ROOT
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /srv/git;
fastcgi_param PATH_INFO $1;
}
}
}
我会确保你的设置尽可能地反映这个.此外,因为我相信Apache正在访问您的/ home / git目录,您需要注意该用户能够这样做.此外,如果您正在使用SELinux,则需要确保进程(httpd)已将适当的上下文添加到/ home,以便它也能够访问此目录.
有关Apache被绊倒的位置的更多详细信息,请查阅/ var / log / httpd / error_log日志文件.
Laravel 5 nginx domain.com/index.php和domain.com/都可以使用.如何重定向/index.php?
在树莓派2上安装了Nginx和PHP 5.6.工作奇妙地减去了我的页面仍然从xyz.com/index.PHP/whatever(WRONG)以及xyz.com/whatever(PERFECT)加载的事实.我不希望/index.PHP加载我的主页.我希望它重定向到/不带index.PHP.这适用于所有子文件夹.我究竟做错了什么??这是我建造的第一台服务器,所以任何帮助都会受到赞赏.谢谢.
网站可用conf:
server {
root /data/something.com/www/something/public;
index index.PHP index.html index.htm;
server_name something.com.local;
# Logging
error_log /data/something.com/logs/error.log;
access_log /data/something.com/logs/access.log;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
# disallow access to hidden files
location ~ /\. {
deny all;
}
# Some locations will never contain PHP files, handle it in the server
location ~ ^/(robots.txt|favicon.ico)(/|$) {
try_files $uri =404;
}
# Pretty urls no /index.PHP (THIS IS WORKING...BUT /index.PHP is still accessible?)
location / {
try_files $uri $uri/ /index.PHP?$query_string;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$/$1 permanent;
}
error_page 404 /index.PHP;
sendfile off;
# PHP
location ~ \.PHP${
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
fastcgi_index index.PHP;
include /etc/Nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# We don't need .ht files with Nginx.
location ~ /\.ht {
deny all;
}
}
解决方法:
正如在nginx redirect loop, remove index.php from url中解释的和Remove index.php from Joomla! URLs with NGINX类似,当从index.PHP重定向时,你必须使用特殊技巧来避免重定向循环:
index index.PHP index.html index.htm;
if ($request_uri ~ "^/(.*)(?<=/)index\.PHP[/?]?((?<=[/?]).*)?$") { return 301 /$1$2; }
nginx - index.php 能访问, index-test.php 能访问, indexa.php 就不能访问了, 为什么?
要弄多个入口文件, index.php 被用, 想起一个叫 indexa.php 的, 结果连不上,
然后有换成 index-test.php , admin.php 等都是好着的,
把 indexa.php 改个名字, 改成 index-test 等都是好的
为什么 indexa.php 就不行呢?
报错
立即学习“PHP免费学习笔记(深入)”;
Firefox 就是一直转圈, 然后就没反应了, chrome 是 无法找到此页面 从 `wwww.xxx.com/index.php` 进入能正常, 把连接换成 `www.xxx.com/indexa.php` 浏览器转会圈, 就又跳回 `www.xxx.com/index.php` 了
回复内容:
要弄多个入口文件, index.php 被用, 想起一个叫 indexa.php 的, 结果连不上,
然后有换成 index-test.php , admin.php 等都是好着的,
把 indexa.php 改个名字, 改成 index-test 等都是好的
为什么 indexa.php 就不行呢?
报错
立即学习“PHP免费学习笔记(深入)”;
Firefox 就是一直转圈, 然后就没反应了, chrome 是 无法找到此页面 从 `wwww.xxx.com/index.php` 进入能正常, 把连接换成 `www.xxx.com/indexa.php` 浏览器转会圈, 就又跳回 `www.xxx.com/index.php` 了
indexa.php 不行错误提示是啥呢?
1,可能没有文件
2,可能没有读写权限
3, 想不到了。。。
nginx - tengine+php-fpm,访问index.php正常,访问index.PHP却会吧php文件下载过来。
server { listen 80; server_name localhost; access_log /data/sites_logs/default.log combined; root /data/sites/default; index index.htm index.html index.php; if ( $query_string ~* ".*[\;''\].*" ){ return 404; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 7d; } ###########################################隐藏index.php location / { index index.htm index.html index.php; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } } ##########################################pathinfo 模式 # location ~ .*\.(php|php5)?$ { # #fastcgi_pass remote_php_ip:9000; # fastcgi_pass unix:/dev/shm/php-cgi.sock; # fastcgi_index index.php; # include fastcgi.conf; # } location ~ \.php$ { fastcgi_pass phpfpm:9000; fastcgi_index index.php; include fastcgi_params; #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量 set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } }
回复内容:
server { listen 80; server_name localhost; access_log /data/sites_logs/default.log combined; root /data/sites/default; index index.htm index.html index.php; if ( $query_string ~* ".*[\;''\].*" ){ return 404; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 7d; } ###########################################隐藏index.php location / { index index.htm index.html index.php; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } } ##########################################pathinfo 模式 # location ~ .*\.(php|php5)?$ { # #fastcgi_pass remote_php_ip:9000; # fastcgi_pass unix:/dev/shm/php-cgi.sock; # fastcgi_index index.php; # include fastcgi.conf; # } location ~ \.php$ { fastcgi_pass phpfpm:9000; fastcgi_index index.php; include fastcgi_params; #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量 set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } }
你php-fpm配置的不符吧 本地应该是 127.0.0.1:9000 你phpfpm:9000 phpfpm是域名还是什么 看看
被mac os分区格式坑了一把。
mac os分区格式有2种:
1、Mac OS 扩展(区分大小写,日志式)
2、Mac OS 扩展(日志式)
我的主盘分区默认是第二种。通过
如果是服务器环境应该不会有这样的问题。
location ~* \.php$
~* 表示不区分大小写.
今天的关于使用nginx通过index.php路由请求和nginx根据请求路径跳转的分享已经结束,谢谢您的关注,如果想了解更多关于centos – 如何使用nginx通过HTTP发布git repo?、Laravel 5 nginx domain.com/index.php和domain.com/都可以使用.如何重定向/index.php?、nginx - index.php 能访问, index-test.php 能访问, indexa.php 就不能访问了, 为什么?、nginx - tengine+php-fpm,访问index.php正常,访问index.PHP却会吧php文件下载过来。的相关知识,请在本站进行查询。
本文标签: