我目前正在我的服务器上运行 Nextcloud,它已经使用端口 443 和 80。我想在同一台机器上安装 Office Online Server,但目前,我必须单独运行它们,因为它们都使用端口 443 和 80。
有什么办法可以让我将它们托管在同一台机器上吗?
答案1
可以尝试nginx的stream进行分流,假设有web1,web2都使用443端口,配置方法如下:nginx.conf配置文件在nginx最后添加如下代码:
流 { 映射 $ssl_preread_server_name $upstream { web1.moeelf.com web1; web2.moeelf.com web2; 默认 web; }
log_format stream '$remote_addr [$time_local] [$ssl_preread_server_name] [$upstream] $status $bytes_sent $bytes_received $session_time';
access_log /var/log/nginx/stream.log stream;
upstream web1 {
server web1:65531;
}
upstream web2 {
server web2:65532;
}
upstream web {
server nginx:4433;
}
server {
listen 443 reuseport;
listen [::]:443 reuseport;
proxy_pass $upstream;
ssl_preread on;
}
}
虚拟主机配置文件将下面的代码保存为sni.conf文件,放置在虚拟主机目录下。nginx的安装方式不同,放置的位置也会不同。一般位于/etc/nginx/conf.d/或者/usr/local/nginx/conf/vhost/下。
服务器{监听65531 ssl http2重用端口;服务器名称web1.moeelf.com;
ssl_certificate /etc/nginx/ssl/web1.moeelf.com/fullchain.cer;
ssl_certificate_key /etc/nginx/ssl/web1.moeelf.com/web1.moeelf.com.key;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
ssl_prefer_server_ciphers on;
#log_format stream '$remote_addr [$time_local] [$ssl_preread_server_name] [$route] $status $bytes_sent $bytes_received $session_time';
access_log /var/log/nginx/web1.moeelf.com.log;
} 服务器 { 监听 65532 ssl http2 重用端口; 服务器名称 web2.moeelf.com;
ssl_certificate /etc/nginx/ssl/web2.moeelf.com/fullchain.cer;
ssl_certificate_key /etc/nginx/ssl/web2.moeelf.com/web2.moeelf.com.key;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
ssl_prefer_server_ciphers on;
#log_format stream '$remote_addr [$time_local] [$ssl_preread_server_name] [$route] $status $bytes_sent $bytes_received $session_time';
access_log /var/log/nginx/web2.moeelf.com.log;
}