【问题标题】:Nginx: Proxy pass meteor application as directoryNginx:代理通过流星应用程序作为目录
【发布时间】:2018-05-25 18:01:56
【问题描述】:

我正在端口 3000 上运行一个流星应用程序,并希望在 nginx 上将其代理传递给地址 example.com/meteor。

我尝试了以下配置,但失败了。当我使用像 meteor.example.com 这样的子域时,它正在工作。

 server {
    listen 80;
    server_name example.com/meteor www.example.com/meteor;

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:3000;
    }
}

除此之外,我还有一个 default 配置,如下所示:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html index.php;

    server_name _;

    location / {
            try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
}

【问题讨论】:

    标签: nginx meteor proxypass


    【解决方案1】:

    您应该在更正的服务器部分下添加 /meteor 位置

       server {
           listen 80;
           server_name example.com www.example.com;
    
           location /meteor {
              proxy_set_header   X-Real-IP $remote_addr;
              proxy_set_header   Host      $http_host;
              proxy_pass         http://127.0.0.1:3000;
           }
    
           #untested
           location ~ /scripts/(.*)$ {
              rewrite ^ /meteor/$1?$args permanent;
           }
        }
    

    【讨论】:

    • 这有效并将我重定向到流星应用程序。但是现在又出现了一个问题:调用页面时,脚本的URL没有被重写。它们是从 URL example.com/scripts 而不是 example.com/meteor/scripts 调用的。
    • @hideous,我不知道你的应用程序结构,但总的来说你有两个选择:在应用程序端更改链接或在 nginx 端使用 rewrite,我'我添加了未经测试的 sn-p
    猜你喜欢
    • 2019-10-18
    • 2019-03-14
    • 2017-02-06
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-12
    • 1970-01-01
    相关资源
    最近更新 更多