[英]Nginx Rewrite Short URL server in Subfolder URL's only
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";
}
?>
我不知道該conf文件如何為您工作,當它用於YOURLS重定向時。 無論如何,這是我對您的問題的建議:
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.