我刚刚使用LEMP堆栈和Nginx服务器在DigitalOcean上部署了Laravel应用程序。
但是,当我导航到服务器IP地址时,出现403 Forbidden错误。然后,当我转到xxx.xx.xxx.xx / public时,即使我已经将root设置为我的公用文件夹,也可以正确看到我的主页。另外,当我单击主页上的任何链接时,都会显示404未找到。
这是我的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;
}
}
答案 0 :(得分:0)
尝试在项目的根目录下将server.php
名称更改为index.php
,并使用以下内容创建一个nginx.conf
文件:
# nginx configuration location ~* (\.css|\.mp4|\.woff|\.js|\.png|\.jpg|\.gif|robots\.txt)$ { } location ~ /public/ { } location / { if (!-e $request_filename){ rewrite ^/(.*)/$ /$1 redirect; } if (!-e $request_filename){ rewrite ^(.*)$ /index.php break; } if (!-e $request_filename){ rewrite ^/(css|js|images|favicon|fonts|videos|storage)/(.*)$ /public/$1/$2 break; } }
答案 1 :(得分:0)
我在服务器上使用它。测试一下:
while ($row = mysqli_fetch_assoc($result)){
$info[$row['converternumber']][$row['zonenumber']][] = $row['codeid'];
}