【发布时间】:2017-03-22 17:04:24
【问题描述】:
我遇到了 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;
}
}
由于某种原因,我无法让应用程序为公共目录提供服务...
希望上面的配置文件能说明我做错了什么。我真的很感谢你的帮助。如果您需要更多信息,请告诉我。
【问题讨论】:
-
Also..logs 显示 404,但没有其他内容
-
应用日志显示什么(监听端口 3000)
-
只是“正在运行...”和端口 3000
-
...如果我删除代理通行证并仅提供应用程序的根目录,则会显示静态页面,但后端 URL 不起作用。
-
在 3000 端口上运行的应用程序中,应该有关于 nginx 连接方式的日志。这些日志是什么?