nginx 403

nginx出现
403 Forbidden
nginx/1.10.3

可以打卡html文件。。当是强制打开index.php。则变成下载。
html文件夹给的777。也提示权限不足。各种权限也给足了

errror.log
2018/04/28 01:14:18 [error] 730#730: *4 directory index of "/var/www/html/" is forbidden, client: 192.168.2.103, server: _, request: "GET / HTTP/1.1", host: "192.168.2.105"

clipboard.png

nginx.conf

user root;
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;
    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/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#    # See sample authentication script at:
#    # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#    # auth_http localhost/auth.php;
#    # pop3_capabilities "TOP" "USER";
#    # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#    server {
#        listen     localhost:110;
#        protocol   pop3;
#        proxy      on;
#    }
# 
#    server {
#        listen     localhost:143;
#        protocol   imap;
#        proxy      on;
#    }
#}

my.conf


server
  {
    listen 80;
    server_name localhost;
    index index.html index.php;
    root /var/www/html/;
      location ~ .*\.(php|php5)?$
    {
      fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
  # access_log off;
    }
    location ~ .*\.(js|css)?$
    {
      expires 15d;
   # access_log off;
    }
    access_log off;
  }
阅读 5.1k
3 个回答

nginx配置好了,出现403 Forbidden主要有两种原因:1、nginx没有访问目录的权限;2、nginx的目录里面没有默认文档,并且没有列出目录的权限。
nginx.conf 贴出来

这个没有就添加,有就把这个贴出来看看

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
        // root /var/www/html; #指定php的根目录
        // fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
}

php 文件出现下载,说明php和nginx 还没配置好

先配置好,应该就可以了.

看到配置里user指定的是root,nginx这里如果配的是root的话需要强制参数启动,所以建议可以放默认的nobody或者新建个www用户,或者干脆删掉让它按默认的就好。
另外这个是搭在本机的么?为啥server_name是localhost?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题