1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 21:18:13 -05:00

proper http->https redirect with custom ports

This commit is contained in:
Kyle Spearrin 2017-11-07 22:35:36 -05:00
parent ed826f4b28
commit c65e08af85
2 changed files with 28 additions and 13 deletions

View File

@ -12,23 +12,26 @@ namespace Bit.Setup
"ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:" +
"AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:@STRENGTH";
public NginxConfigBuilder(string domain, bool ssl, bool selfSignedSsl, bool letsEncrypt)
public NginxConfigBuilder(string domain, string url, bool ssl, bool selfSignedSsl, bool letsEncrypt)
{
Domain = domain;
Url = url;
Ssl = ssl;
SelfSignedSsl = selfSignedSsl;
LetsEncrypt = letsEncrypt;
}
public NginxConfigBuilder(string domain)
public NginxConfigBuilder(string domain, string url)
{
Domain = domain;
Url = url;
}
public bool Ssl { get; private set; }
public bool SelfSignedSsl { get; private set; }
public bool LetsEncrypt { get; private set; }
public string Domain { get; private set; }
public string Url { get; private set; }
public bool DiffieHellman { get; private set; }
public bool Trusted { get; private set; }
@ -90,6 +93,7 @@ namespace Bit.Setup
# Parameter:SelfSignedSsl={SelfSignedSsl}
# Parameter:LetsEncrypt={LetsEncrypt}
# Parameter:Domain={Domain}
# Parameter:Url={Url}
# Parameter:DiffieHellman={DiffieHellman}
# Parameter:Trusted={Trusted}
@ -100,7 +104,7 @@ server {{
if(Ssl)
{
sw.WriteLine($@" return 301 https://$server_name$request_uri;
sw.WriteLine($@" return 301 ${Url}$request_uri;
}}
server {{

View File

@ -86,10 +86,7 @@ namespace Bit.Setup
ssl = certBuilder.Ssl; // Ssl prop can get flipped during the build
var url = ssl ? $"https://{domain}" : $"http://{domain}";
var nginxBuilder = new NginxConfigBuilder(domain, ssl, selfSignedSsl, letsEncrypt);
nginxBuilder.BuildForInstaller();
Console.Write("(!) Do you want to use the default HTTP (80) and HTTPS (443) ports? (y/n): ");
Console.Write("(!) Do you want to use the default ports for HTTP (80) and HTTPS (443)? (y/n): ");
var defaultPorts = Console.ReadLine().ToLowerInvariant() == "y";
int httpPort = default(int), httpsPort = default(int);
if(!defaultPorts)
@ -97,14 +94,25 @@ namespace Bit.Setup
Console.Write("(!) HTTP port: ");
if(int.TryParse(Console.ReadLine().ToLowerInvariant().Trim(), out httpPort))
{
Console.Write("(!) HTTPS port: ");
if(int.TryParse(Console.ReadLine().ToLowerInvariant().Trim(), out httpsPort))
if(ssl)
{
url += (":" + httpsPort);
Console.Write("(!) HTTPS port: ");
if(!int.TryParse(Console.ReadLine().ToLowerInvariant().Trim(), out httpsPort))
{
if(httpPort != 443)
{
url += (":" + httpsPort);
}
}
else
{
Console.WriteLine("Invalid HTTPS port.");
httpPort = default(int);
}
}
else
else if(httpPort != 80)
{
Console.WriteLine("Invalid HTTPS port.");
url += (":" + httpPort);
}
}
else
@ -116,6 +124,9 @@ namespace Bit.Setup
Console.Write("(!) Do you want to use push notifications? (y/n): ");
var push = Console.ReadLine().ToLowerInvariant() == "y";
var nginxBuilder = new NginxConfigBuilder(domain, url, ssl, selfSignedSsl, letsEncrypt);
nginxBuilder.BuildForInstaller();
var environmentFileBuilder = new EnvironmentFileBuilder
{
DatabasePassword = Helpers.SecureRandomString(32),
@ -272,7 +283,7 @@ namespace Bit.Setup
var domain = uri.Host;
var nginxBuilder = new NginxConfigBuilder(domain);
var nginxBuilder = new NginxConfigBuilder(domain, url);
nginxBuilder.BuildForUpdater();
var appSettingsBuilder = new AppSettingsBuilder(url, domain);