我有一个 DigitalOcean 液滴,我试图在其中托管多个服务器。准确地说,我有以下设置: 1. 我的个人站点(使用serve
托管的 React 前端)位于 localhost:5000
2. 我的 Jekyll 博客使用Bundler托管(命令:) ,位于 localhost:4000/blog/
3. 一个 nodejs 项目在 localhost:3031使用pm2托管bundle exec jeykll serve
当我使用上面带有 localhost 的 URL 从服务器测试它们中的每一个时curl
,我得到了正确的响应。
我有一个用 namecheap 注册的域,比如abcd.me,用 cloudflare 来管理我的 DNS 设置。按照他们的说明,我更新了我在 namecheap 上的设置以使用 Cloudflare 的名称服务器。
目前对我有用的是:
- 我可以在https://abcd.me
访问我的个人网站
- 我可以在 http://{droplet-ip}:3031 访问我的 nodejs 项目
我无法实现的目标: - 在https://blog.abcd.me
访问我的博客
目前,访问https://blog.abcd.me会再次返回我的个人站点,只是 URL 以“blog.”为前缀。我的 nginx 配置如下所示:
server {
listen 3030 default_server;
listen [::]:3030 default_server;
server_name {server-ip};
index index.html index.htm index.nginx-debian.html;
location / {
proxy_pass http://localhost:3031;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name blog.abcd.me www.blog.abcd.me;
location / {
proxy_pass http://localhost:4000/blog/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 80;
listen [::]:80;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name abcd.me www.abcd.me;
# location / {
# # First attempt to serve request as file, then
# # as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
#}
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/abcd.me/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/abcd.me/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}
我无法弄清楚我哪里出错了。有人可以帮助我吗?