Prestashop 安装期间出现 Nginx 403 Forbiden

Prestashop 安装期间出现 Nginx 403 Forbiden

我正在尝试在我的 Centos 7 服务器上安装 Prestashop,并使用 Nginx 作为 Web 服务器。

以下是我采取的步骤:

wget https://download.prestashop.com/download/releases/prestashop_1.7.4.2.zip

unzip prestashop_1.7.4.2.zip  ((gives 3 files, including prestapshop.zip))

unzip prestapshop.zip -d /var/www/example.com/public_html

chmod 755 /var/www/example.com/public_html/ -R

chown nginx:nginx * /var/www/example.com/public_html -R

但当我尝试访问https://example.com我得到一个403 禁止回复。

这是我的/etc/nginx/sites-available/example.com.conf文件内容:

 server{
   root /var/www/example.com/public_html;

   server_name example.com www.example.com MY_SERVER_IP;

   location / {
      index index.html index.htm;
      #try_files $uri $uri/ =404;
   }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

   error_page 500 502 503 504 /50x.html;
   location = /50x.html {
      root html;
   }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
 server{
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot



   listen 80;

   server_name example.com www.example.com MY_SERVER_IP;
    return 404; # managed by Certbot


}

谢谢你们的帮助。

干杯

附言:我以 root 身份运行了所有这些命令

附注2:我的 example.com.conf 文件中的 Certbot 部分是由 Certbot(安装 SSL 证书的软件)自动添加的

以下是我尝试访问我的网站后收到的 nginx 错误日志:

2018/08/30 05:53:04 [error] 27114#0: *6 directory index of "/var/www/example.com/public_html/install/" is forbidden, client: MY_SERVER_IP, server: lemeilleur$
2018/08/30 05:53:56 [error] 27114#0: *9 directory index of "/var/www/example.com/public_html/install/" is forbidden, client: MY_SERVER_IP, server: lemeilleur$
2018/08/30 06:30:26 [error] 27114#0: *12 directory index of "/var/www/example.com/public_html/install/" is forbidden, client: MY_SERVER_IP, server: lemeilleu$

(“lemeilleu” 是我的网站 URL 的一部分,但我不知道 lemeilleu$ 对应的是什么)

输出ls -Z /var/www/example.com/public_html/

drwxr-xr-x nginx nginx ?                                admin
drwxr-xr-x nginx nginx ?                                app
-rwxr-xr-x nginx nginx ?                                autoload.php
drwxr-xr-x nginx nginx ?                                bin
drwxr-xr-x nginx nginx ?                                cache
drwxr-xr-x nginx nginx ?                                classes
-rwxr-xr-x nginx nginx ?                                composer.lock
drwxr-xr-x nginx nginx ?                                config
drwxr-xr-x nginx nginx ?                                controllers
-rwxr-xr-x nginx nginx ?                                docker-compose.yml
drwxr-xr-x nginx nginx ?                                docs
drwxr-xr-x nginx nginx ?                                download
-rwxr-xr-x nginx nginx ?                                error500.html
-rwxr-xr-x nginx nginx ?                                images.inc.php
drwxr-xr-x nginx nginx ?                                img
-rwxr-xr-x nginx nginx ?                                index.php
-rwxr-xr-x nginx nginx ?                                init.php
drwxr-xr-x nginx nginx ?                                install
-rwxr-xr-x nginx nginx ?                                INSTALL.txt
drwxr-xr-x nginx nginx ?                                js
-rwxr-xr-x nginx nginx ?                                LICENSES
drwxr-xr-x nginx nginx ?                                localization
drwxr-xr-x nginx nginx ?                                mails
drwxr-xr-x nginx nginx ?                                modules
drwxr-xr-x nginx nginx ?                                override
drwxr-xr-x nginx nginx ?                                pdf
-rwxr-xr-x nginx nginx ?                                robots.txt
drwxr-xr-x nginx nginx ?                                src
drwxr-xr-x nginx nginx ?                                themes
drwxr-xr-x nginx nginx ?                                tools
drwxr-xr-x nginx nginx ?                                translations
drwxr-xr-x nginx nginx ?                                upload
drwxr-xr-x nginx nginx ?                                var
drwxr-xr-x nginx nginx ?                                vendor
drwxr-xr-x nginx nginx ?                                webservice

最后,/etc/php-fpm.d/www.conf文件:

user = nginx

group = nginx

listen.owner = nginx

listen.group = nginx

listen = 127.0.0.1:9000

答案1

我终于找到了解决这个问题的方法。即使在运行时nginx -t如果一切正常,并不意味着它实际上与你的 nginx.conf 内容有关(或你的站点.com.conf内容)。

因此,我的问题是最常见的问题,即遇到 Nginx 和 403 Forbiden 消息,即,正如你在我的 .conf 文件中注意到的那样,该行index index.html index.htm;放置得不好,它必须是全局的,因此在地点层,像这样:

 server{
   root /var/www/example.com/public_html;

   server_name example.com www.example.com MY_SERVER_IP;

   index index.php index.html index.htm;

   location / {
      #try_files $uri $uri/ =404;
   }

相关内容