我遇到了proxy_pass的问题。请求进来。它被路由到我的应用程序运行的端口(3000),但总是返回404.如果我向后端api url发出请求,那些返回200.例如: www.mysite.com/api ---返回200 但: www.mysite.com/#/about ---返回404 www.mysite.com/或www.mysite.com ---返回404
如何让nginx服务于端口3000上运行的应用程序?
nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
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;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
# ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascrip$
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/默认站点启用-
server {
listen 80;
server_name mysite.com www.mysite.com;
return 301 https://$host$request_uri;
location ~ /.well-known {
allow all;
}
}
#HTTPS
server{
listen 443;
ssl on;
server_name mysite.com www.mysite.com;
include snippets/ssl-mysite.com.conf;
include snippets/ssl-params.conf;
location / {
expires max;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Proto http;
}
}
出于某种原因,我无法让应用程序服务于公共目录......
希望上面的配置文件能显示我的错误。我非常感谢你的帮助。如果您需要更多信息,请告诉我。
答案 0 :(得分:0)
使用proxy_pass
端点
/api/
location /api/ {
...
proxy_pass http://127.0.0.1:3000;
...
}