NGINX配置,用于从现有的短链接Web服务创建短链接服务

时间:2018-07-01 14:28:57

标签: nginx laravel-5.6 laravel-forge

我有一个现有的短链接服务,域名长为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/*;

1 个答案:

答案 0 :(得分:0)

假设您希望两个网站都提供相同的内容:

server_name ~^longname.com|sh.rt$;

这可能会导致SSL证书出现问题,但是您表示不想使用单独的服务器块。如果您是我,我会将其配置为具有相同root目录的额外服务器块。另外,这更像是一个serverfault问题。

有关其他文档,请参见: