Nginx/Php爱好者的
我在Nginx上运行了一个Yourls安装程序,使用以下.conf文件可以很好地工作。重定向工作,数据库是从apache安装复制过来的,一切都很好。
但是,在旧服务器上,我在一个子目录中运行了另一个简单的shortURL服务。它有许多使用url.com/p/0aexvibr样式创建的短URL
它们都运行在名为"p“的子目录中,所有的链接看起来都是这样的,它们都是纯文件,在顶行只有一个URL。
我需要的是让Nginx重定向url.com/p/0aexvibr之类的URL,并忽略下面Yourls重写规则所重定向的URL。将它们带到/p/中的php脚本,然后打开并重定向用户链接的文件中的URL (在本例中0aexvibr包含url http://google.com),有人可以帮助设置吗?
当前会议
server {
listen 80;
server_name url.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /var/www/html/url;
charset utf-8;
}
location / {
try_files $uri $uri/ /yourls-loader.php;
index index.php;
include /etc/nginx/conf.d/php-fpm;
}
include /etc/nginx/drop;
}
下面是show.php的内容
<?php
if($_GET['id']){
$id = addslashes($_GET['id']);
if(file_exists("urls/$id"))
{
$url = file_get_contents("urls/$id");
header("location:".$url);
} else {
echo "Error : invalid hash";
}
} else {
echo "Error : no hash";
}
?>
发布于 2014-12-24 20:38:56
对于YOURLS重定向,我不知道conf文件是如何为您工作的。无论如何,这是我对你的问题的建议:
server {
listen 80;
server_name url.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
charset utf-8;
##the next two locations for the old service which calls the show.php
location ~ ^/p/(.+\.php)$ {
alias /var/www/html/url/$1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
location /p {
alias /var/www/html/url/;
try_files $uri $uri/ /p/show.php;
}
##the next two locations for the yourls configuration, expecting it to be in the root directory
location ~ ^/(.+\.php)$ {
alias /var/www/html/url/$1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
location / {
alias /var/www/html/url/;
index index.php;
try_files $uri $uri/ yourls-loader.php;
}
}
https://stackoverflow.com/questions/27254299
复制相似问题