我在数字海洋上有一个dropplet,我有一个node.js
应用和nginx
。
所以,我安装了nginx,然后在/etc/nginx/sites-available/
我创建了一个名为api
的新文件,其中包含以下内容:
server {
server_name api.my-website.com;
location / {
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $proxy_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:9000; // this is where the node app lives
}
}
在我创建之后我恢复了nginx但是如果我去api.my-website.com我什么都没看到(我的api上有一个着陆页/),但如果我去my-website.com:9000我请参阅api.my-website.com上的登陆。
有人可以解释我,我做错了吗?
答案 0 :(得分:0)
您未将/etc/nginx/sites-available/api
文件包含在/etc/nginx/nginx.conf
中。您需要在/etc/nginx/sites-available/api
/etc/nginx/nginx.conf
模块中包含http
,然后重新启动或重新加载nginx。您的/etc/nginx/nginx.conf
可能看起来像
http {
# other lines for logging, gzip, etc.
# other include may here
# Your include as following
include /etc/nginx/sites-available/api;
}