Prestashop 安裝期間 Nginx 403 Forbiden

Prestashop 安裝期間 Nginx 403 Forbiden

我正在嘗試在我的 Centos 7 伺服器上安裝 Prestashop,並使用 Nginx 作為網頁伺服器。

以下是我採取的步驟:

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 身分執行了所有這些命令

p.s2:我的 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」是我網站網址的一部分,但我不知道 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 內容有關(或yoursite.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;
   }

相關內容