鍍金池/ 問答/Linux  HTML/ nginx 403

nginx 403

nginx出現(xiàn)
403 Forbidden
nginx/1.10.3

可以打卡html文件。。當(dāng)是強(qiáng)制打開index.php。則變成下載。
html文件夾給的777。也提示權(quán)限不足。各種權(quán)限也給足了

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;
  }
回答
編輯回答
孤星

nginx配置好了,出現(xiàn)403 Forbidden主要有兩種原因:1、nginx沒有訪問目錄的權(quán)限;2、nginx的目錄里面沒有默認(rèn)文檔,并且沒有列出目錄的權(quán)限。
nginx.conf 貼出來

這個(gè)沒有就添加,有就把這個(gè)貼出來看看

# 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的默認(rèn)端口是9000
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
}
2017年1月28日 17:48
編輯回答
離夢(mèng)

php 文件出現(xiàn)下載,說明php和nginx 還沒配置好

先配置好,應(yīng)該就可以了.

2018年6月1日 01:02
編輯回答
礙你眼

看到配置里user指定的是root,nginx這里如果配的是root的話需要強(qiáng)制參數(shù)啟動(dòng),所以建議可以放默認(rèn)的nobody或者新建個(gè)www用戶,或者干脆刪掉讓它按默認(rèn)的就好。
另外這個(gè)是搭在本機(jī)的么?為啥server_name是localhost?

2018年9月9日 19:05