【问题标题】:"403 Forbidden nginx/1.14.0 (Ubuntu) "“403 禁止 nginx/1.14.0 (Ubuntu)”
【发布时间】:2020-09-01 15:26:15
【问题描述】:

我已经为 nginx 配置了多个位置,一个用于 laravel 项目,另一个用于本机 php 项目。 Laravel 项目运行良好,但第二个位置似乎给出了:

“403 禁止 nginx/1.14.0 (Ubuntu)”

这是我的默认文件:

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /var/www/html/washyapi/public;
        try_files $uri $uri/ index.php$is_args$args;
        index index.html index.htm index.php;
        server_name 167.71.239.178;
        location / {
        try_files   $uri $uri/  index.php$is_args$args;
                try_files $uri $uri/ /index.php?$query_string;
        #index index.php;       
        }
        location /admin {
        root /var/www/html/;
        #autoindex on;
        #autoindex_exact_size off;
        index index.php;
        #try_files $uri  /index.php?$query_string;      
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

        location /phpmyadmin {
           root /usr/share/;
           index index.php index.html index.htm;
           location ~ ^/phpmyadmin/(.+\.php)$ {
                   try_files $uri =404;
                   root /usr/share/;
                   fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                   fastcgi_index index.php;
                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                   include /etc/nginx/fastcgi_params;
           }
           location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                   root /usr/share/;
           }
        }
    }

【问题讨论】:

    标签: php laravel nginx http-status-code-403


    【解决方案1】:

    经过几天的挣扎,这里是我为使它工作所做的工作。 这是让两个应用程序工作的工作配置,其中一个应用程序存在于另一个应用程序的子目录中。 默认文件:

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    root /var/www/top/public;
    
    index index.html index.htm index.php;
    
    server_name _;
    
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    
    location /nested {
        alias /var/www/nested/public;
        try_files $uri $uri/ @nested;
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
    }
    
    location @nested {
        rewrite /nested/(.*)$ /nested/index.php?/$1 last;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
    

    }

    别忘了重启nginx服务器:

    service nginx restart
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-28
      • 2020-06-27
      • 1970-01-01
      • 2016-02-02
      • 2019-06-07
      • 2019-04-17
      • 2019-05-29
      相关资源
      最近更新 更多