我有3个Node.js应用。客户端,管理员和API。我还有子域:example.com,admin.example.com和api.example.com。 我也有nginx配置,但它不起作用(在我看来) 当我输入api.example.com时,它会加载example.com的内容,但是当我用端口编写子域时,它的工作原理是:api.example.com:8081
在客户端,我使用angular.js,也许这里有问题,但我不这么认为......
这是我的nginx conf:/ etc / nginx / sites-avaliable / default:
server {
listen 80;
server_name example.com;
rewrite ^ https://$http_host$request_uri? permanent;
location / {
proxy_pass http://127.0.0.1:443;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
}
}
server {
listen 80;
server_name api.example.com;
rewrite ^ https://$http_host$request_uri? permanent;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
}
}
server {
listen 80;
server_name admin.example.com;
rewrite ^ https://$http_host$request_uri? permanent;
location / {
proxy_pass http://127.0.0.1:8082;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
}
}
enter code here