Nginx centos7 被禁止

标签 nginx centos centos7

我安装了 nginx,但我的日志文件中有这个错误

[error] 2658#2658: *2 directory index of "/usr/share/nginx/html/" is 
forbidden, client: 192.168.1.2, server: localhost, request: "GET / HTTP/1.1", host: "192.168.1.6"

我的文件配置是这样的:
user  nginx;

worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    server{
        listen 80;
        root /usr/share/nginx/html;
        index index.php index.html;
        server_name 192.168.1.10;
        location ~ \.php$ {
#root           /usr/share/nginx/html;
fastcgi_pass   127.0.0.1:9000;
#       include fastcgi_params;
#       fastcgi_pass unix:/var/run/php-fpm.sock;
#      include /etc/nginx/fastcgi_params;
#        fastcgi_pass  127.0.0.1:80;
        fastcgi_index index.php;
fastcgi_param  SCRIPT_FILENAME $fastcgi_script_name;
 include        fastcgi_params;
        }
         location ~ /\.ht {
                         deny all;
         }
    }

}

`

但我有 403 被禁止。
我尝试过了:
  • chmod -R 775/usr/src
  • chmod o+x/usr
  • chown -R nginx:nginx/usr/share

  • 我不知道我在做什么:(

    谢谢你的帮助,
    希望你有个美好的一天。

    戴维德。

    最佳答案

    我解决它。
    这是我的新 nginx.conf

    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include   /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    
    access_log  /var/log/nginx/access.log  main;
    
    sendfile        on;
    #tcp_nopush     on;
    
    keepalive_timeout  65;
    
    #gzip  on;
    
    include /etc/nginx/conf.d/*.conf;
        server{
                listen 80;
                root /usr/share/nginx/html/;
                index index.php index.html index.htm;
                server_name 192.168.1.6;
                location ~ \.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
    
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    }
                     location ~ /\.ht {
                                         deny all;
                     }
            }
    
    }
    

    关于Nginx centos7 被禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44338724/

    相关文章:

    ubuntu - TradingView WebHook API 不起作用,是什么阻止了 POST 请求?

    php - 尝试安装 mcrypt 扩展时出错

    postgresql - 在没有 postgresql-server 的情况下重启 PostgreSQL

    bash - Ansible playbook 不显示来自某个 shell 管道的输出

    仅在需要升级时停止服务的 Ansible 方法

    python - ZMQ python 套接字从上下文捕获异常

    ruby-on-rails - 如何配置 nginx 以在域中安装 Rails 应用程序并在/blog/中安装 WordPress?

    ssl - 我所有的网站都返回 301 而不是 200

    linux - Linux服务器上崩溃后如何自动重新启动elasticsearch搜索?

    linux - CentOS 网络服务器 : Best practice for creating SSH user that is friendly with Nginx