首页 > 解决方案 > Laravel 403 Forbidden nginx/1.14.0 (Ubuntu) in Nginx Digital Ocean

问题描述

我将我的 Laravel-5.8 项目部署到 DigitalOcean,它可以正常工作:

http://laravelproject.net

但是因为我使用的是 Azure AD 和 Socialite。Azure AD 不允许使用 http,但允许使用 https

/etc/nginx/sites-available/default

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html/laravelproject;

# Add index.php to the list if you are using PHP
    # index index.php index.html index.htm;
# index index.php index.html index.htm index.nginx-debian.html;

server_name laravelproject.net;

location / {
	# First attempt to serve request as file, then
	# as directory, then fall back to displaying a 404.
	 try_files $uri $uri/ /index.php$is_args$args;
	# try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
	include snippets/fastcgi-php.conf;
#
#	# With php-fpm (or other unix sockets):
	fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
#	# With php-cgi (or other tcp sockets):
#	fastcgi_pass 127.0.0.1:9000;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
	deny all;
}
}

我也有:

/etc/nginx/sites-available/default

server {
    listen 80;
    listen [::]:80;

    server_name laravelproject.net;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name laravelproject.net;
    root /var/www/html/peopleedge;

    ssl_certificate /etc/letsencrypt/live/laravelproject.net/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/laravelproject.net/privkey.pem;
    
    ssl_protocols TLSv1.2;
	ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
	ssl_prefer_server_ciphers on;

	add_header X-Frame-Options "SAMEORIGIN";
	add_header X-XSS-Protection "1; mode=block";
	add_header X-Content-Type-Options "nosniff";

	index index.php index.html index.htm index.nginx-debian.html;

    charset utf-8;

    location / {
            try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
    }

    location ~ /.well-known {
            allow all;
    }
}

当我尝试运行该项目时,出现此错误:

Laravel 403 禁止 nginx/1.14.0 (Ubuntu)

请问我该如何解决?

谢谢你。

标签: laraveldigital-ocean

解决方案


I know its late already but for any other person who may need it,below code config helps me resolve the isssue 

`server {
    listen 80;
    server_name yourip or domain;
    root /var/www/html/public;
    index index.php;
    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
`

also remember to reload nginx with ` sudo systemctl reload nginx
`

推荐阅读