gpt4 book ai didi

ubuntu - 如何在 Ubuntu 16.04 上使用 Nginx 设置多个 https 虚拟服务器 block ?

转载 作者:行者123 更新时间:2023-12-04 19:14:05 24 4
gpt4 key购买 nike

我尝试了几个在线教程但无济于事。
这是我拥有的文件:

/etc/nginx/sites-available/默认:

# HTTP - redirect all traffic to HTTPS
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}

# HTTPS - proxy all requests to the Node app
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name codytpatterson.com;

# Use the Let's Encrypt certificates
ssl_certificate /etc/letsencrypt/live/codytpatterson.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/codytpatterson.com/privkey.pem;

# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5000/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}

/etc/nginx/sites-available/mobile.codytpatterson.com:
# HTTP - redirect all traffic to HTTPS
server {
listen 80;
listen [::]:80 ipv6only=on;
return 301 https://$host$request_uri;
}

# HTTPS - proxy all requests to the Node app
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mobile.codytpatterson.com;

# Use the Let's Encrypt certificates
ssl_certificate /etc/letsencrypt/live/mobile.codytpatterson.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mobile.codytpatterson.com/privkey.pem;

# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:6000/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}

这两个文件在 /etc/nginx/sites-enabled/ 中都有符号链接(symbolic link)。 .当我运行 sudo nginx -t有人告诉我,我有重复的应用程序试图监听同一个端口(我认为这不会发生,因为我只有一个服务器文件作为默认值列出)我觉得我缺少一些我不知道的东西。也许它与代理有关?有谁在 nginx 方面有经验的人可以启发我吗?这是我的 nginx 配置文件,以防万一它也有任何用处:

/etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}

如果我暂时只想要一个子域,也许还有更好的方法来做到这一点。但最终我希望能够在此服务器上托管多个网站,因此了解如何按照我的方式进行操作(使用单独的文件)以及在单个文件中设置额外的子域会很有帮助如果这是实现这一目标的更简单方法。

最佳答案

我认为问题在于您对端口 80 的重定向缺少 server_name配置,所以它们实际上是重复的。尝试添加它,看看它是否有所作为。

关于ubuntu - 如何在 Ubuntu 16.04 上使用 Nginx 设置多个 https 虚拟服务器 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44876872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com