【问题标题】:Nginx configurationNginx 配置
【发布时间】:2015-03-20 05:06:25
【问题描述】:

在下面的代码中,我通过 nginx 重定向到 http://127.0.0.1:3000/app1/namelist/name=xyz。当我点击http://127.0.0.1:80/ 时,它会抛出一个错误“Cannot GET/”。我该如何解决这个问题?

如果我直接点击127.0.0.1:3000/app1/namelist/name=xyz,它应该通过 nginx 重定向。是否可以在nginx中配置?

#user  nobody; worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024; 
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;  
    upstream node_entry {
        server 127.0.0.1:3000; 
    }

    server {    
        listen       80;
        server_name  127.0.0.1;

        location / {
            #root   html;
            #index  index.html index.htm;
            #return 503;
            proxy_pass     http://node_entry/;
        }
    }
}

【问题讨论】:

  • 你说的是/app1/namelist,而上游只说127.0.0.1:3000
  • 您能否澄清一下:80/ 是否需要命中 :3000/app1/namelist/name=xyz?代理传递会将路径发送到上游。 / 仍将是 / 在 3000 端口上。

标签: node.js nginx url-redirection


【解决方案1】:

好吧,就 nginx 而言,我会从您的代理传递行中删除尾部斜杠,因此它看起来像这样:

proxy_pass http://node_entry;

如果这不起作用,则响应必须来自您的上游。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-22
    • 2017-07-25
    • 2012-12-31
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多