代码之家  ›  专栏  ›  技术社区  ›  code-8

禁止使用Ngix 403-Ubuntu

  •  0
  • code-8  · 技术社区  · 6 年前

    我的nginx一直投403

    我打开了日志,我看到了

    2019/10/23 12:08:25[错误]28945#28945:*18禁止使用“/home/bheng/snake river/public/”目录索引,客户端:20.231.19.250,服务器:默认,请求:“GET/HTTP/1.1”,主机:“167.99.234.85”

    然后我进入我的虚拟机我运行这个

    chgrp www-data public/
    service nginx reload
    

    现在看看这个

    drwxr-xr-x  5 root     www-data 4.0K Oct 23 12:15 public/
    

    刷新页面仍然保持原样

    http://167.99.234.85/
    

    ps-ef | grep nginx公司

    root     29332     1  0 12:15 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
    root     29369 29164  0 12:16 pts/2    00:00:00 tail -f /var/log/nginx/default-error.log
    www-data 29769 29332  0 12:40 ?        00:00:00 nginx: worker process
    root     29771 29278  0 12:42 pts/3    00:00:00 grep nginx
    

    sudo ufw应用程序列表

    Available applications:
      Nginx Full
      Nginx HTTP
      Nginx HTTPS
      OpenSSH
    

    我也试过了 $uri $uri/

    location / {
        try_files $uri $uri /index.php?$query_string;
        add_header 'Access-Control-Allow-Origin' '*';
    }
    

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        add_header 'Access-Control-Allow-Origin' '*';
    }
    

    相同的结果


    nginx.conf格式

    user www-data;
    worker_processes auto;
    pid /run/nginx.pid;
    include /etc/nginx/modules-enabled/*.conf;
    
    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 Settings
        ##
    
        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;
    
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
    }
    
    2 回复  |  直到 6 年前
        1
  •  -1
  •   code-8    6 年前

    不正确的文件权限是“403禁止”错误的另一个原因。标准制定 七百五十五 对于目录和 六百四十四 for文件建议与NGINX一起使用。NGINX用户还需要是文件的所有者。

    识别NGINX用户

    首先,您需要确定运行NGINX的用户身份。为此,请使用以下命令:

    ps -ef | grep nginx
    

    对于任何NGINX工作进程,请检查第一列:

    在本例中,NGINX工作进程作为用户NGINX运行。

    设置文件所有权

    转到网站文档根目录上方的目录。例如,如果您的网站的文档根目录是 /usr/share/nginx/example.com网站 /usr/共享/nginx 使用命令:

    cd /usr/share/nginx
    

    使用以下命令将所有文件的所有权从此处更改为nginx用户:

    sudo chown -R nginx:nginx
    

    设置权限

    将此位置的每个目录的权限设置为 七百五十五 使用命令:

    sudo chmod 755 [directory name]
    

    例如,要设置 example.com网站 目录,命令是:

    sudo chmod 755 example.com
    

    然后转到web文档根目录:

    cd example.com
    

    使用以下命令更改此目录中所有文件的权限:

    sudo chmod 644 *
    

    https://www.ionos.com/community/server-cloud-infrastructure/nginx/solve-an-nginx-403-forbidden-error/

    推荐文章