我在我的服務器上面跑了兩個node應用程序,分別一個端口2368跑的是ghost博客,一個端口8000跑的是我的demo程序。想要一級域名zhangruojun.com用來訪問博客,二級域名demo.zhangruojun.com用來訪問demo程序。
首先,在你的域名供應商那里添加一條二級域名記錄
nginx 配置
server {
listen 80;
server_name zhangruojun.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368; }
}
server {
listen 80;
server_name demo.zhangruojun.com;
location / { proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8000; }
}