nginx 403 forbidden under Debian 7

发布于 2022-08-26 15:50:16 字数 3942 浏览 15 评论 0

在Debian Wheezy本地安装了nginx + php5-fpm却遭遇 403 forbidden,遇此问题,甚是不明,还请列位支点招。


输入localhost/phpinfo.php显示正常

可输入localhost就跳出403错误

nginx错误日志显示

2013/07/05 16:27:06 [error] 7351#0: *12 directory index of
"/var/www/install/" is forbidden, client: 127.0.0.1, server:
localhost, request: "GET /install/ HTTP/1.1", host: "localhost"

权限方面 /var/www -R 775

nginx配置方面:

#cat /etc/nginx/nginx.conf

    user www-data;  
    worker_processes 1;  
    pid /var/run/nginx.pid;

    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;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Virtual Host Configs
        ##

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

#cat /etc/nginx/sites-enabled/default

    server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        #root /usr/share/nginx/www;
        root /var/www;
        index index.html index.php;

        # Make site accessible from http://localhost/
        server_name localhost;
        server_name_in_redirect off;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ /index.html;
                try_files $uri $uri/ /index.php?$args;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

    # Rewrite for Fork CMS   

    location ~ ^/(backend|install|api(\/\d.\d)?(\/client)?).*\.php$ {
    # backend/install/api are existing dirs, but should all pass via the front
    try_files $uri $uri/ /index.php?$args;   }

    location ~ ^(.+\.php)(.*)$ {
      include fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;   }   

    # gzip   
    gzip on;   
    gzip_disable "MSIE [1-6]\.(?!.*SV1)"; # disables gzip compression for browsers that don't support it (in this case MS Internet Explorer before version 6 SV1).   gzip_http_version 1.1;   gzip_vary on; # This sets the response header Vary: Accept-Encoding. Some proxies have a bug in that they serve compressed content to browsers that don't support it. By setting the Vary: Accept-Encoding header, you instruct proxies to store both a compressed and uncompressed version of the content.   gzip_comp_level 6;   gzip_proxied any;   gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js ;   gzip_buffers 16 8k;

      # client caching   
    location ~ \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
    expires 31d;
    add_header Pragma "public";
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";       }

    # End of Fork

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

婴鹅 2022-09-02 15:50:16

解决了,答案意思和@依云的一样,不同的是方法,就是去掉

try_files $uri $uri/ /index.php?$args;

里的

$uri/

原文请参照这里

我一直都在从未离去 2022-09-02 15:50:16
autoindex on;
涫野音 2022-09-02 15:50:16

那的document_root里没有index.html和index.php

爺獨霸怡葒院 2022-09-02 15:50:16

需要开启:
autoindex: on;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文