nginx - 用于从现有短链接 Web 服务创建短链接服务的 NGINX 配置
问题描述
我有一个现有的长域名短链接服务longname.com/Wsdfsdf
。当访问者单击此链接时,它会重定向到longname.com/order-details/customer-id/3435345345435
现在我有一个短域名sh.rt
,并且希望每个longname.com/*
人的行为都与sh.rt/*
结果,当访问者访问 sh.rt/Wsdfsdf
时,它将重定向到longname.com/order-details/customer-id/3435345345435
相同的longname.com/Wsdfsdf
位置。
通过这样做,我不必为sh.rt
我尝试将 servername 中的域名添加到 NGINX 配置文件,但问题可能是longname.com
默认 ssl 并且sh.rt
没有。
我的 Nginx 文件是:
include forge-conf/mydomain.com/before/*;
server {
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name .mydomain.com;
root /home/forge/mydomain.com/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/mydomain.com/330472/server.crt;
ssl_certificate_key /etc/nginx/ssl/mydomain.com/330472/server.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers '...';
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/mydomain.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mydomain.com/after/*;
解决方案
假设您希望两个站点都提供相同的内容:
server_name ~^longname.com|sh.rt$;
这可能会导致您的 SSL 证书出现问题,但您声明您不想使用单独的服务器块。如果我是你,我会将其配置为具有相同目录的额外服务器块root
。这也是一个服务器故障问题。
有关其他文档,请参阅:
推荐阅读
- azure - 将文件复制到 Azure DevOps 中的 zip 文件夹
- vue.js - 有没有办法让 vue 组件自毁?
- c# - 远程服务器返回错误:(400) 错误请求。(从 WCF 到 ASP.NET)
- polymer - 如何在组件之间共享异步方法 - LitElement
- android - 有没有办法在后台每 15 分钟运行一次服务?
- java - 如何通过外部 API 或命令提示符调用 eclipse 插件?
- swift - MapView 在运行时变为 nil
- javascript - TypeError:第一个参数必须是 string、Buffer、ArrayBuffer、Array 或 Array-like Object 类型之一。在cryptoJS中接收到类型对象
- python-3.x - 这个链表插入实现是如何工作的?
- javascript - 当我使用 jQuery ddSlick JS 选择一个选项时,页面不断加载