【问题标题】:Unable to proxy_pass mailcather with nginx无法使用 nginx 代理_pass mailcather
【发布时间】:2014-11-02 09:14:03
【问题描述】:

我有以下 nginx 配置

upstream domain1 {
  server 127.0.0.1:3000;
  server 127.0.0.1:3001;
}




server {
  listen   80;
  server_name demo.domain.com;

  root   /var/apps/myapp/public;

  location / {
                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_redirect off;

                if (-f $request_filename/index.html) {
                                 rewrite (.*) $1/index.html break;
                }

                if (-f $request_filename.html) {
                                 rewrite (.*) $1.html break;
                }

                if (!-f $request_filename) {
                                 proxy_pass http://domain1;
                                 break;
                }
  }

 location /mail_us1 {
                proxy_pass       http://127.0.0.1:1080;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
 }


}

我正在尝试在我的服务器上设置mailcatcher(mailcatcher 在1080 端口运行)

由于我在 nginx 方面的经验有限,我假设以下指令会很好用

 location /mail_us1 {
                    proxy_pass       http://127.0.0.1:1080;
                    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
                    proxy_set_header Host $http_host;
     }

但不幸的是,我无法获得所需的输出,并且我不断登陆 nginx 页面上的状态

No Dice

The message you were looking for does not exist, or doesn't have content of this type.

谁能告诉我我做错了什么

注意:

- curl http://localhost:1080 (work )

- iptables -L (is empty)

【问题讨论】:

    标签: nginx mailcatcher


    【解决方案1】:

    这对我有用:

    location /mailcatcher {
      rewrite /mailcatcher/(.*) /$1 break;
      proxy_pass http://mailcatcher/;
    }
    
    location ~ ^/assets {
      proxy_pass http://mailcatcher;
    }
    
    location ~ ^/messages {
      proxy_pass http://mailcatcher;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
    

    【讨论】:

    • 你对hosts文件做了什么吗?你如何设置http://mailcatcher 是什么?
    猜你喜欢
    • 2020-01-08
    • 2019-05-08
    • 2021-06-13
    • 1970-01-01
    • 2022-09-26
    • 2021-12-01
    • 2023-02-02
    • 1970-01-01
    • 2020-08-19
    相关资源
    最近更新 更多