403禁止-Nginx-甲骨文云实例

时间:2018-08-04 12:45:04

标签: nginx oracle-cloud-infrastructure-classic

例如,我希望公共访问我的上载文件夹:

  

mydomain.com/uploads /

例如,它需要显示目录的内容:

  

mydomain2.com/uploads/id/file.png

这应该显示file.png

但是当我尝试

  

mydomain2.com/uploads /

它给了我

  

403禁止   nginx / 1.15.1

我的nginx配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

# mydomain1.com
server {
    listen   443;
    ssl                 on;
    ssl_certificate     /home/opc/Crt/bundle.crt;
    ssl_certificate_key /home/opc/Crt/mydomain1.key;

    server_name mydomain1;
    #root <root_path>;

    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

#mydomain2.com

server {

  # We are listening on the default port.
  listen 443;

  ssl                 on;
  ssl_certificate     /home/opc/Crt/bundle.crt;
  ssl_certificate_key /home/opc/Crt/mydomain2.com.key;

  # These are the domains we listen on.
  server_name mydomain2.com;

  # The root path
  #root <physical_path>

  location /uploads {
    #internal;
    alias /home/opc/folder/uploads;
    #try_files $uri /uploads/;
    #autoindex on;
    #index index.html;
    #autoindex on;
    #autoindex_exact_size off;
 }

  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Forwarded-For $remote_addr;
  }
}
  

注意:2个域指向我的实例,因此我将一个用于3001端口,将另一个用于3000端口,并且我已经将755分配给/ folder / uploads,将644赋予了uploads文件夹内的所有文件

1 个答案:

答案 0 :(得分:0)

好像您的nginx进程没有访问该文件夹/文件的权限,请检查/home/opc/folder/index.html上的权限。进行chown nginx:nginx /home/opc/folder/index.html并运行相同的请求,看看它如何处理,如果仍然存在问题,则您可能具有一些SELinux之类的内核访问控制;如果您在CentOS上运行并且第一次测试失败,请执行chcon -R --reference=/usr/share/nginx/html/ /home/opc/folder,然后重试。