布置的服务器用的nginx做代理转发,接口监听的3000端口,nginx监听80做转发。
系统是centos 7。接口用的nodejs写的,pm2做进程管理。
现在的问题是我直接请求域名,接口返回403,但是如果我在域名后面加上80或者3000的端口号,接口能顺利返回数据。
这是nginx的配置
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name fate.com;
#charset koi8-r;
location / {
root html;
index index.html index.htm;
# url 切换时始终返回index.html
try_files $uri /home/blog/reactindex.html;
#access_log /var/log/nginx/host.access.log main;
}
location /api/ {
#proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# rewrite /server(.+)$ $1 break;
# proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://127.0.0.1:3000; # 这里要和最上面upstream后的应用名一致,可以自定义
access_log /var/log/nginx/api.log main;
error_log /var/log/nginx/api.error.log warn;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
api是我的接口路径。
比如说我写www.baidu.com,接口就403,如果写www.baidu.com:80或者www.baidu.com:3000就能正常请求,这是什么问题造成的?
把
改成
试试