【问题标题】:configure nginx as a webserver with puma for application without domain将 nginx 配置为带有 puma 的网络服务器,用于没有域的应用程序
【发布时间】:2019-04-26 18:26:47
【问题描述】:

我有一个云服务器,我的应用程序在我的服务器上。我目前没有域,但我想使用 nginx 作为我的应用程序的网络服务器。所以我在 nginx 中为这个应用程序配置了以下内容。

我没有域,所以 example.com 只是用作 proxy_pass url,但它似乎不起作用。

/etc/nginx/sites-enabled/example.com

    upstream puma_example {
      server unix:///home/deploy/sites/example.com/shared/tmp/sockets/example.sock;
    }

    server {
      listen 80 ;
      server_name example.com;

      gzip on;
      gzip_http_version 1.0;
      gzip_disable "msie6";
      gzip_vary on;
      gzip_min_length 1100;
      gzip_buffers 64 8k;
      gzip_comp_level 3;
      gzip_proxied any;
      gzip_types text/css text/xml application/x-javascript application/atom+xml text/mathml text/plain text/vnd.sun.j2me.app-descriptor text/vnd.wap.wml text/x-component;

      root /home/deploy/sites/example.com/current/public;
      access_log /home/deploy/sites/example.com/current/log/nginx.access.log;
      error_log /home/deploy/sites/example.com/current/log/nginx.error.log info;

      location ^~ /assets/ {
        gzip_static on;
        expires max;
        add_header Cache-Control public;
      }

      try_files $uri/index.html $uri @puma_example;
      location @puma_example {
        proxy_set_header X-Forwarded-Proto http;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass http://puma_example;
      }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 25M;
  keepalive_timeout 10;
}

当我运行我的 rails 应用程序时,我可以看到它正在运行,但我似乎无法通过 nginx 链接它。所以当我http://example.com 时,它不会加载我的应用程序。

我错过了什么?如何让我的应用程序通过 nginx 在本地连接,而我的云服务器上没有域名。

感谢任何帮助。

【问题讨论】:

    标签: nginx webserver reverse-proxy puma proxypass


    【解决方案1】:

    你可以使用你的ip地址,这里是一个简化的例子。

    upstream 127.0.0.1 {
       server unix:///var/run/yourapp.sock;
    }
    
    server {
      listen 80;
      server_name 127.0.0.1;
      root /var/www/yourapp/current/public;
    
     location / {
         proxy_pass http://127.0.0.1/; 
         proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 2016-04-13
      • 2018-02-03
      • 2014-10-03
      • 1970-01-01
      相关资源
      最近更新 更多