为什么Nginx会从默认目录而不是新目录中正确提供文件?

时间:2018-01-15 18:39:03

标签: nginx centos

安装

操作系统:CentOS 7.4

服务器:Nginx 1.12.2

问题:我的nginx安装在默认目录/usr/share/nginx/html中提供没有问题的文件。不幸的是,当我使用我创建的新文件夹/www/html时,我收到403错误。我应该寻找什么?

虽然所有者不同,但我的权限对于两个文件夹都是相同的。

原始默认文件夹

drwxr-xr-x. 13 root root 155 Jan 8 09:25 usr

新默认文件夹

drwxr-xr-x. 3 first first 18 Jan 15 10:45 www

我正在使用下面的精简server.conf文件,它可以正常工作。

events {}

http {

    server {
        listen       80;
        server_name  mydomain.com;
        root         /usr/share/nginx/html;
    }

}

但是当我更改server.conf以使用此目录/www/html时,我收到403错误。

提前感谢您的帮助!我是一个菜鸟,甚至不确定在文件权限之外的哪个位置。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。

解。您必须在conf.d文件夹

中创建test.example.com.conf
server {
    listen       80;
    #listen       *:80;
    server_name  test.example.com;

    # note that these lines are originally from the "location /" block
    root   /var/www/test.example.com/;
    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # Remove trailing slash to please routing system.
    if (!-d $request_filename) {
            rewrite     ^/(.+)/$ /$1 permanent;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

文件:

systemctl restart nginx.service

重启服务器String s = "[\"A\",\"B\",\"0\",\"1\"]"; Gson gson = new GsonBuilder().create(); String[] arr = gson.fromJson(s, String[].class); // {"A","B","0","1"}

相关问题