我有一个 meern 应用程序,前端似乎工作正常,而后端根本不工作。
后端应该在 127.0.0.1:3000/api 上工作,但给出以下错误消息,它总是重定向到 127.0.0.1:3000:
2018/07/25 15:32:43 [error] 31172#0: *4 open() "/var/www/Interface-2.0/Client/dist/50x.html" failed (2: No such file or directory), client: 130.63.1.192, server: edafos.eng.yorku.ca, request: "POST /api/auth/register HTTP/1.1", upstream: "https://127.0.0.1:3000/auth/register", host: "edafos.eng.yorku.ca", referrer: "https://edafos.eng.yorku.ca/register"
我尝试了一些方法,例如将 /api 添加到上游和 proxy_pass 中。我还在位置 ^~ /api 块中评论了重写。一切都不成功,我总是在日志中收到相同的错误。
这是我的完整配置文件:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_edafos {
server 127.0.0.1:3000;
}
#Point http requests to https
server {
listen 0.0.0.0:80;
server_name edafos.eng.yorku.ca;
server_tokens off;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name edafos.eng.yorku.ca;
ssl_certificate /etc/letsencrypt/live/my.app.ca/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my.app.ca/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
ssl_session_cache shared:SSL:1m;
root /var/www/Interface-2.0/Client/dist;
index index.html;
location / {
try_files $uri /index.html;
error_page 405 = $uri;
}
location ^~ /api {
rewrite /api/(.*)$ /$1 break;
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 X-Ssl on;
proxy_pass https://app_edafos;
proxy_redirect off;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
有人对如何解决这个问题有建议吗?另外,请求的 URL 如下所示https://edafos.eng.yorku.ca/api/auth/register