【发布时间】:2019-04-12 12:06:47
【问题描述】:
我刚刚使用带有 Nginx 服务器的 LEMP 堆栈在 DigitalOcean 上部署了我的 Laravel 应用程序。
但是,当我导航到我的服务器 IP 地址时,我收到 403 Forbidden 错误。然后当我转到 xxx.xx.xxx.xx/public 时,即使我已经将我的根目录设置为我的公用文件夹,我也可以正确看到我的主页。另外,当我点击主页上的任何链接时,它会显示 404 Not Found。
这是我的 etc/nginx/sites-available/default:
我做错了什么?请不要将我的问题标记为重复,因为我看到大多数类似的主题他们忘记将 Index.php 添加到他们的索引列表或忘记将他们的根链接到他们的公用文件夹,但是我做的都是正确的。
我的配置文件:
# Default server configuration
#
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/public/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name 159.65.192.29;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
}
# 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.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
【问题讨论】:
-
你能用你的 nginx 配置作为代码而不是截图来更新你的帖子吗?
-
由于某种原因,我无法在我的 Ubuntu 环境中复制/粘贴。
-
你的整个 Laravel 项目都在
/var/www/html/吗? -
你记得编辑配置后重新加载 nginx 吗?
-
我用代码块更新了我的问题。是的,我的项目位于 /var/www/html/。