subadmained Nginx返回403禁止unicorn / rails设置

时间:2015-05-08 02:03:54

标签: ruby-on-rails linux nginx unicorn

我正在尝试通过nginx和unicorn将我的子域路由到运行rails应用程序的数字海洋服务器。在某些计算机上,应用程序加载正常。在其他(和大多数)站点路由到IP并返回nginx 403错误。在/var/log/nginx/error.log的日志中看起来像这样:     [错误] 1618#0:* 68禁止“path / to / app”目录索引,客户端:24.114.44.135,服务器:_,

这是我的/etc/nginx/nginx.conf文件:

user **user**;
worker_processes 4;
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;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    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;

    ##
    # Logging Settings
    ##

    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/javascript text/xml application/xml application/xml+rss text/javascrip$

    ##
    # Virtual Host Configs
    ##
        include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Deployer与我(成功)使用capistrano部署的用户相同 这是在/ var / www:

运行ls -la的结果
total 16
drwxrwx---  4 deployer deployer 4096 Apr 23 14:40 .
drwxr-xr-x 13      775 www-data 4096 Apr 22 17:30 ..
drwxrwx---  2 deployer deployer 4096 Apr 23 14:40 html
drwxrwxr-x  4 deployer deployer 4096 May  7 20:11 my_app_name

子文件夹/文件似乎都归部署者所有,是运行的结果:

chown -R deployer:deployer

我也尝试过:

sudo chmod -R 755 /var/www 

正如一些博客/其他问题所暗示的那样......不可否认,我现在在命令和权限方面都有所损失。我的linux /生产经验相当薄弱。 我有一些类似问题的答案,包括将配置更改为nginx用户www-data和各种组合。拖尾错误日志是禁止的* number目录的各种形式。这个错误只在我尝试将其从IP移动到子域后才开始发生。

编辑/ etc / nginx / sites-enabled / appstuff:

upstream unicorn_my_app_name_production {
server unix:/tmp/unicorn.my_app_name_production.sock fail_timeout=0;

}



server {
listen 80;


client_max_body_size 4G;
keepalive_timeout 10;
error_page 500 502 504 /500.html;
error_page 503 @503;

server_name sub.domain.com;
root path/to/public/folder;
autoindex on;
try_files $uri/index.html $uri @unicorn_my_app_name_production;
index index.html index.htm;
location @unicorn_my_app_name_production {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn_my_app_name_production;
# limit_req zone=one;
    access_log /var/log/nginx/my_app_name_production.access.log;
error_log /var/log/nginx/my_app_name_production.error.log;
}

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

location = /50x.html {
root html;
}
location = /404.html {
root html;
location @503 {
  error_page 405 = /system/maintenance.html;
  if (-f $document_root/system/maintenance.html) {
  rewrite ^(.*)$ /system/maintenance.html break;
}
rewrite ^(.*)$ /503.html break;
}

if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
 return 405;
}

if (-f $document_root/system/maintenance.html) {
 return 503;
}

}

1 个答案:

答案 0 :(得分:0)

您发布了nginx配置文件的错误部分。

中有文件
/etc/nginx/sites-enabled/

指向您的个人配置。在这些文件中,您应该看到server块。这是一个简单的例子:

server {
    server_name sub.domain.com;

    location /images {
        root /var/www
        default_type image/jpeg;
    }
}

重要的是要注意,仅当server_name值与当前请求匹配时,才应用特定服务器块的规则。您需要做的是找到当前站点的配置,并确保正确设置server_name键值。然后,当您通过IP直接访问网站时,您的网站应该像以前一样工作。