403禁止在ubuntu中使用nginx

403禁止在ubuntu中使用nginx,nginx,Nginx,我读过: server { listen 443; server_name localhost; ssl on; ssl_certificate /home/attolee/sslkey/example.crt; ssl_certificate_key /home/attolee/sslkey/example.key; ssl_session_time

我读过:

 server {
            listen 443;
            server_name localhost;
            ssl on;
            ssl_certificate /home/attolee/sslkey/example.crt;
            ssl_certificate_key /home/attolee/sslkey/example.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
            ssl_prefer_server_ciphers on;

            location / {
                    root /home/attolee;
                    index index.html;
            }

            location /hi/ {
                    root /home/attolee;
                    index hi.html;
            }
   }
->/data/images/example.png

 server {
            listen 443;
            server_name localhost;
            ssl on;
            ssl_certificate /home/attolee/sslkey/example.crt;
            ssl_certificate_key /home/attolee/sslkey/example.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
            ssl_prefer_server_ciphers on;

            location / {
                    root /home/attolee;
                    index index.html;
            }

            location /hi/ {
                    root /home/attolee;
                    index hi.html;
            }
   }
->/data/www/some/example.html

 server {
            listen 443;
            server_name localhost;
            ssl on;
            ssl_certificate /home/attolee/sslkey/example.crt;
            ssl_certificate_key /home/attolee/sslkey/example.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
            ssl_prefer_server_ciphers on;

            location / {
                    root /home/attolee;
                    index index.html;
            }

            location /hi/ {
                    root /home/attolee;
                    index hi.html;
            }
   }
因此,我的nginx配置:

 server {
            listen 443;
            server_name localhost;
            ssl on;
            ssl_certificate /home/attolee/sslkey/example.crt;
            ssl_certificate_key /home/attolee/sslkey/example.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
            ssl_prefer_server_ciphers on;

            location / {
                    root /home/attolee;
                    index index.html;
            }

            location /hi/ {
                    root /home/attolee;
                    index hi.html;
            }
   }
我想要

 server {
            listen 443;
            server_name localhost;
            ssl on;
            ssl_certificate /home/attolee/sslkey/example.crt;
            ssl_certificate_key /home/attolee/sslkey/example.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
            ssl_prefer_server_ciphers on;

            location / {
                    root /home/attolee;
                    index index.html;
            }

            location /hi/ {
                    root /home/attolee;
                    index hi.html;
            }
   }
  • 访问/home/attolee/index.html
  • 访问/home/attolee/hi/hi.html
  • 现在1个工作,2个失败,403个被禁止

     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }
    
    错误日志告诉我是
    13:权限被拒绝

     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }
    
    所以我检查了/home/attolee和/home/attolee/hi/,以及hi.html

     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }
    
    drwxr-xr-x  6 attolee attolee 4096 Nov  2 17:08 attolee/
    drw-rw-rw- 2 root    root    4096 Nov  2 17:12 hi/
    -rw-rw-rw- 1 root    root      24 Nov  2 17:12 hi.html
    
    然后使用htop is root检查nginx进程用户属性

     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }
    

    如何解决此问题?

    首先,在您的示例中,您应该执行以下操作:

     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }
    
    root /home/attolee;
    index index.html hi.html
    location / {
             try_files $uri $uri/ =404;  
    }
    

    其次,您不需要以root身份运行nginx。例如,在nginx.conf中,您可以将其更改为www数据。您必须移动/home/hi-inside/home/attolee/并将/home/attolee/设置为正确的所有者。

    我遇到了这个问题,对我来说,问题是关于中的nginx配置

     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }
    
    /etc/nginx/sites-available
    

    我的错误是,我定义了一些未命名的文件和文件夹位置。因此,我编辑了位置并开始解决问题。

    目录需要
    x
    permission@AlexeyTen使用
    x
    更改
    其他
    权限,它可以工作。
     server {
                listen 443;
                server_name localhost;
                ssl on;
                ssl_certificate /home/attolee/sslkey/example.crt;
                ssl_certificate_key /home/attolee/sslkey/example.key;
                ssl_session_timeout 5m;
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
                ssl_prefer_server_ciphers on;
    
                location / {
                        root /home/attolee;
                        index index.html;
                }
    
                location /hi/ {
                        root /home/attolee;
                        index hi.html;
                }
       }