【问题标题】:Laravel 403 Forbidden nginx/1.14.0 (Ubuntu) in Nginx Digital OceanLaravel 403 Forbidden nginx/1.14.0 (Ubuntu) in Nginx Digital Ocean
【发布时间】:2020-06-27 13:54:44
【问题描述】:

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

http://laravelproject.net

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

/etc/nginx/sites-available/默认

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/默认

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)

请问如何解决?

谢谢。

【问题讨论】:

    标签: laravel digital-ocean


    【解决方案1】:
    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
    `
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-31
      • 2021-02-28
      • 2020-06-04
      • 2017-06-10
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      相关资源
      最近更新 更多