首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx 403在安装前禁止使用Nginx 403

Nginx 403在安装前禁止使用Nginx 403
EN

Server Fault用户
提问于 2018-08-30 04:39:49
回答 1查看 1.2K关注 0票数 0

我正试图在我的Centos 7服务器上安装Prestashop,其中Nginx是一个with服务器。

以下是我所采取的步骤:

代码语言:javascript
复制
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禁止的响应。

这是my /etc/nginx/sites现有/example.com.conf文件内容:

代码语言:javascript
复制
 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


}

谢谢你们的帮助。

干杯

p.s:我将所有这些命令作为root运行

p.s2:我的example.com.conf文件中的Certbot部件是由Certbot (安装SSL证书的软件)自动添加的。

Also这里是我尝试访问我的网站后获得的nginx错误日志:

代码语言:javascript
复制
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/的输出

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
user = nginx

group = nginx

listen.owner = nginx

listen.group = nginx

listen = 127.0.0.1:9000
EN

回答 1

Server Fault用户

发布于 2018-08-30 14:30:24

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

因此,我的问题是遇到了Nginx和403禁止消息,也就是说,正如您可以在我的.conf文件中注意到的那样,行index index.html index.htm;不是很好的位置,它必须是全局的,所以在位置层内外都是如此,如下所示:

代码语言:javascript
复制
 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;
   }
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/928641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档