Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run the game on HTTP port instead of 443 #229

Closed
Stevie0427 opened this issue Apr 26, 2024 · 4 comments
Closed

Run the game on HTTP port instead of 443 #229

Stevie0427 opened this issue Apr 26, 2024 · 4 comments

Comments

@Stevie0427
Copy link

When I run the game with the varible --http-port , it will automaticlly use the port 443 and redirect the HTTP request to port 443, but the port 443 of my server is used by nginx to deploy some other services. I would likevto know how to deploy the game on an another port instead of 443, thanks.

@finnbear
Copy link
Member

finnbear commented Apr 26, 2024

We have fixed this in our private upstream repository but haven't open-sourced it yet.

Until then, consider editing this line to use whatever port numbers you want:

let ports = (self.http_port.unwrap_or(default_ports.0), default_ports.1);

// (http, https)
let ports = (123, 456);

@Stevie0427
Copy link
Author

Stevie0427 commented Apr 26, 2024

OK, so how can I disable HTTPS? Because I would like to use nginx to proxy it and enable HTTPS on the source site make the configuration more complex.

@finnbear
Copy link
Member

Hmm, that's a different code change. Go here:

#[cfg(not(debug_assertions))]
let http_app = Router::new()
.fallback_service(get(async move |uri: Uri, host: TypedHeader<axum::headers::Host>, headers: reqwest::header::HeaderMap| {
if let Err(response) = limit_content_length(&headers, 16384) {
return Err(response);
}
let mut parts = uri.into_parts();
parts.scheme = Some(Scheme::HTTPS);
let authority = if https_port == Options::STANDARD_HTTPS_PORT {
Authority::from_str(host.0.hostname())
} else {
// non-standard port.
Authority::from_str(&format!("{}:{}", host.0.hostname(), https_port))
}.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response())?;
parts.authority = Some(authority);
Uri::from_parts(parts)
.map(|uri| if http_port == Options::STANDARD_HTTP_PORT { Redirect::permanent(&uri.to_string()) } else { Redirect::temporary(&uri.to_string()) })
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response())
}));
#[cfg(debug_assertions)]
let http_app = app;
let http_server = axum_server::bind(SocketAddr::from(([0, 0, 0, 0], http_port)))
.addr_incoming_config(addr_incoming_config.clone())
.http_config(http_config.clone())
.serve(http_app.into_make_service_with_connect_info::<SocketAddr>());
#[cfg(debug_assertions)]
error!("http server stopped: {:?}", http_server.await);
#[cfg(not(debug_assertions))]
let rustls_config = if let Some((certificate_path, private_key_path)) = certificate_paths {
let rustls_config = axum_server::tls_rustls::RustlsConfig::from_pem_file(
certificate_path,
private_key_path,
).await.unwrap();
let renewal_rustls_config = rustls_config.clone();
let certificate_path = certificate_path.to_owned();
let private_key_path = private_key_path.to_owned();
tokio::spawn(async move {
let mut old_expiry = server_util::ssl::certificate_expiry(&certificate_path).unwrap();
let mut governor = tokio::time::interval(Duration::from_secs(24 * 60 * 60));
loop {
// Every day.
governor.tick().await;
match server_util::ssl::certificate_expiry(&certificate_path) {
Ok(new_expiry) => {
if new_expiry > old_expiry {
warn!("renewing SSL certificate...");
if let Err(e) = renewal_rustls_config.reload_from_pem_file(&certificate_path, &private_key_path).await {
error!("failed to renew SSL certificate: {}", e);
} else {
old_expiry = new_expiry;
}
} else {
log::info!("SSL certificate not in need of renewal.");
}
}
Err(e) => error!("failed to get SSL certificate expiry: {}", e)
}
}
});
rustls_config
} else {
warn!("Using self-signed certificate in place of trusted certificate.");
axum_server::tls_rustls::RustlsConfig::from_pem(
include_bytes!("certificate.pem").as_slice().into(),
include_bytes!("private_key.pem").as_slice().into(),
).await.unwrap()
};
#[cfg(not(debug_assertions))]
let https_server = axum_server::bind_rustls(SocketAddr::from(([0, 0, 0, 0], https_port)), rustls_config)
.addr_incoming_config(addr_incoming_config.clone())
.http_config(http_config)
.serve(app.into_make_service_with_connect_info::<SocketAddr>());
#[cfg(not(debug_assertions))]
tokio::select! {
result = http_server => {
error!("http server stopped: {:?}", result);
}
result = https_server => {
error!("https server stopped: {:?}", result);
}
}

Remove all #[cfg(debug_assertions)]'s and delete all lines right after #[cfg(not(debug_assertions))]'s. Debug was HTTP-only, this change just hardcodes HTTP-only.

@Stevie0427
Copy link
Author

Thanks for your answering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants