我使用Node.js托管一些网站并使用Nginx进行制作,以便我可以在同一台服务器上托管多个网站。我刚刚开始遇到这个问题,例如,如果我去examplesite1
它工作正常,如果我去www.examplesite1
它工作得很好,如果我去examplesite2
它工作正常,但当我转到www.examplesite2
时,它会显示examplesite1
上的内容。这是我正在使用的配置:
nginx.conf
:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server_names_hash_bucket_size 64;
}
conf.d/blog.jakewalker.xyz.conf
:
server {
listen 80;
server_name blog.jakewalker.xyz;
location / {
proxy_pass http://ghost:2368; # this is to a docker container
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;
}
}
conf.d/jakewalker.xyz.conf
:
server {
listen 80;
server_name jakewalker.xyz;
location / {
proxy_pass http://sites:2100; # also for a docker container
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;
}
}
我按照本指南https://www.digitalocean.com/community/tutorials/how-to-host-multiple-node-js-applications-on-a-single-vps-with-nginx-forever-and-crontab了解了如何进行设置。
我不确定它是否会有所帮助,但这是我网站的DNS:
A jakewalker.xyz {ip of server}
CNAME www.jakewalker.xyz @
A blog.jakewalker.xyz {ip of server}
我做错了吗?