我已经运行了 YOURLS 服务器来为我的公司托管短网址,以便我们可以向我们的客户提供短网址。
我正在使用 nginx,对于域的根目录,如果他们没有使用正确的短 url,我想重定向到我们的网站。因此 example.com/218a 重定向到该短网址指向的任何内容,但 example.com 转到我们的网站 @ domain.com。
现在,我正在使用一个 index.html 页面,它只是一个元刷新来重定向,但我想我应该能够在 nginx 配置中做到这一点,它可能会更好。
如果可能的话,有人可以帮助我以正确的方式在服务器级别实现这一点,而不是使用元刷新吗?
我已经尝试了一些我在这里找到的例子,但它们似乎都不起作用。
这是我的配置文件以供参考。
server {
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name http://domain.com;
location / {
#YOURLS
try_files $uri $uri/ /yourls-loader.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php5-fpm-sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
Run Code Online (Sandbox Code Playgroud)