gpt4 book ai didi

Nginx:无法访问该站点;权限配置?

转载 作者:行者123 更新时间:2023-12-05 00:09:34 25 4
gpt4 key购买 nike

在 VPS 上设置 nginx 的过程中,出现标题中描述的一般性“无法访问站点”错误。这是 /etc/nginx/sites-available/domainname.com

server {
listen 80 default_server;
listen [::]:80 default_server;

root /var/www/domainname.com/public;
index index.php index.html index.htm

server_name domainname.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}

这在 /etc/nginx/sites-enabled 中是符号链接(symbolic link)的。 VPS 的域名和 IP 地址都返回相同的错误。我记得几个月前遇到过类似的问题,最终需要更改某些文件权限,甚至写下了发生的事情,但找不到我关于此事的笔记。不过,我怀疑权限再次成为问题的一部分。

据我所知,问题可能出在对 nginx 目录或我的 php 目录或运行 nginx 进程的用户的内容的权限上。为此,这是 ls -la 为/etc/nginx 返回的内容:

 ls -la -R /etc/nginx
/etc/nginx:
total 64
drwxr-xr-x 6 root root 4096 May 29 22:32 .
drwxr-xr-x 98 root root 4096 May 29 22:34 ..
drwxr-xr-x 2 root root 4096 Oct 27 2016 conf.d
-rw-r--r-- 1 root root 1077 Apr 26 2016 fastcgi.conf
-rw-r--r-- 1 root root 1007 Apr 26 2016 fastcgi_params
-rw-r--r-- 1 root root 2837 Apr 26 2016 koi-utf
-rw-r--r-- 1 root root 2223 Apr 26 2016 koi-win
-rw-r--r-- 1 root root 3957 Apr 26 2016 mime.types
-rw-r--r-- 1 root root 1462 Apr 26 2016 nginx.conf
-rw-r--r-- 1 root root 180 Apr 26 2016 proxy_params
-rw-r--r-- 1 root root 636 Apr 26 2016 scgi_params
drwxr-xr-x 2 root root 4096 May 29 23:25 sites-available
drwxr-xr-x 2 root root 4096 May 29 23:28 sites-enabled
drwxr-xr-x 2 root root 4096 May 29 22:32 snippets
-rw-r--r-- 1 root root 664 Apr 26 2016 uwsgi_params
-rw-r--r-- 1 root root 3071 Apr 26 2016 win-utf

/etc/nginx/conf.d:
total 8
drwxr-xr-x 2 root root 4096 Oct 27 2016 .
drwxr-xr-x 6 root root 4096 May 29 22:32 ..

/etc/nginx/sites-available:
total 12
drwxr-xr-x 2 root root 4096 May 29 23:25 .
drwxr-xr-x 6 root root 4096 May 29 22:32 ..
-rw-r--r-- 1 root root 2129 May 29 22:57 domainname

/etc/nginx/sites-enabled:
total 8
drwxr-xr-x 2 root root 4096 May 29 23:28 .
drwxr-xr-x 6 root root 4096 May 29 22:32 ..
lrwxrwxrwx 1 root root 34 May 29 22:32 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 40 May 29 23:28 domainname -> /etc/nginx/sites-available/domainname

/etc/nginx/snippets:
total 16
drwxr-xr-x 2 root root 4096 May 29 22:32 .
drwxr-xr-x 6 root root 4096 May 29 22:32 ..
-rw-r--r-- 1 root root 422 Apr 26 2016 fastcgi-php.conf
-rw-r--r-- 1 root root 217 Apr 26 2016 snakeoil.conf

以及/etc/php 的输出:

ls -la -R /etc/php
/etc/php:
total 12
drwxr-xr-x 3 root root 4096 May 29 22:34 .
drwxr-xr-x 98 root root 4096 May 29 22:34 ..
drwxr-xr-x 5 root root 4096 May 29 22:34 7.0

/etc/php/7.0:
total 20
drwxr-xr-x 5 root root 4096 May 29 22:34 .
drwxr-xr-x 3 root root 4096 May 29 22:34 ..
drwxr-xr-x 3 root root 4096 May 29 22:34 cli
drwxr-xr-x 4 root root 4096 May 29 22:40 fpm
drwxr-xr-x 2 root root 4096 May 29 22:34 mods-available

/etc/php/7.0/cli:
total 84
drwxr-xr-x 3 root root 4096 May 29 22:34 .
drwxr-xr-x 5 root root 4096 May 29 22:34 ..
drwxr-xr-x 2 root root 4096 May 29 22:34 conf.d
-rw-r--r-- 1 root root 70655 May 11 23:12 php.ini

/etc/php/7.0/cli/conf.d:
total 8
drwxr-xr-x 2 root root 4096 May 29 22:34 .
drwxr-xr-x 3 root root 4096 May 29 22:34 ..
lrwxrwxrwx 1 root root 39 May 29 22:34 10-opcache.ini -> /etc/php/7.0/mods-available/opcache.ini
lrwxrwxrwx 1 root root 35 May 29 22:34 10-pdo.ini -> /etc/php/7.0/mods-available/pdo.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-calendar.ini -> /etc/php/7.0/mods-available/calendar.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-ctype.ini -> /etc/php/7.0/mods-available/ctype.ini
lrwxrwxrwx 1 root root 36 May 29 22:34 20-exif.ini -> /etc/php/7.0/mods-available/exif.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-fileinfo.ini -> /etc/php/7.0/mods-available/fileinfo.ini
lrwxrwxrwx 1 root root 35 May 29 22:34 20-ftp.ini -> /etc/php/7.0/mods-available/ftp.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-gettext.ini -> /etc/php/7.0/mods-available/gettext.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-iconv.ini -> /etc/php/7.0/mods-available/iconv.ini
lrwxrwxrwx 1 root root 36 May 29 22:34 20-json.ini -> /etc/php/7.0/mods-available/json.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-mbstring.ini -> /etc/php/7.0/mods-available/mbstring.ini
lrwxrwxrwx 1 root root 41 May 29 22:34 20-pdo_pgsql.ini -> /etc/php/7.0/mods-available/pdo_pgsql.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-pgsql.ini -> /etc/php/7.0/mods-available/pgsql.ini
lrwxrwxrwx 1 root root 36 May 29 22:34 20-phar.ini -> /etc/php/7.0/mods-available/phar.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-posix.ini -> /etc/php/7.0/mods-available/posix.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-readline.ini -> /etc/php/7.0/mods-available/readline.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-shmop.ini -> /etc/php/7.0/mods-available/shmop.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sockets.ini -> /etc/php/7.0/mods-available/sockets.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sysvmsg.ini -> /etc/php/7.0/mods-available/sysvmsg.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sysvsem.ini -> /etc/php/7.0/mods-available/sysvsem.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sysvshm.ini -> /etc/php/7.0/mods-available/sysvshm.ini
lrwxrwxrwx 1 root root 41 May 29 22:34 20-tokenizer.ini -> /etc/php/7.0/mods-available/tokenizer.ini

/etc/php/7.0/fpm:
total 96
drwxr-xr-x 4 root root 4096 May 29 22:40 .
drwxr-xr-x 5 root root 4096 May 29 22:34 ..
drwxr-xr-x 2 root root 4096 May 29 22:34 conf.d
-rw-r--r-- 1 root root 4421 May 11 23:12 php-fpm.conf
-rw-r--r-- 1 root root 70997 May 29 22:40 php.ini
drwxr-xr-x 2 root root 4096 May 29 22:34 pool.d

/etc/php/7.0/fpm/conf.d:
total 8
drwxr-xr-x 2 root root 4096 May 29 22:34 .
drwxr-xr-x 4 root root 4096 May 29 22:40 ..
lrwxrwxrwx 1 root root 39 May 29 22:34 10-opcache.ini -> /etc/php/7.0/mods-available/opcache.ini
lrwxrwxrwx 1 root root 35 May 29 22:34 10-pdo.ini -> /etc/php/7.0/mods-available/pdo.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-calendar.ini -> /etc/php/7.0/mods-available/calendar.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-ctype.ini -> /etc/php/7.0/mods-available/ctype.ini
lrwxrwxrwx 1 root root 36 May 29 22:34 20-exif.ini -> /etc/php/7.0/mods-available/exif.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-fileinfo.ini -> /etc/php/7.0/mods-available/fileinfo.ini
lrwxrwxrwx 1 root root 35 May 29 22:34 20-ftp.ini -> /etc/php/7.0/mods-available/ftp.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-gettext.ini -> /etc/php/7.0/mods-available/gettext.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-iconv.ini -> /etc/php/7.0/mods-available/iconv.ini
lrwxrwxrwx 1 root root 36 May 29 22:34 20-json.ini -> /etc/php/7.0/mods-available/json.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-mbstring.ini -> /etc/php/7.0/mods-available/mbstring.ini
lrwxrwxrwx 1 root root 41 May 29 22:34 20-pdo_pgsql.ini -> /etc/php/7.0/mods-available/pdo_pgsql.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-pgsql.ini -> /etc/php/7.0/mods-available/pgsql.ini
lrwxrwxrwx 1 root root 36 May 29 22:34 20-phar.ini -> /etc/php/7.0/mods-available/phar.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-posix.ini -> /etc/php/7.0/mods-available/posix.ini
lrwxrwxrwx 1 root root 40 May 29 22:34 20-readline.ini -> /etc/php/7.0/mods-available/readline.ini
lrwxrwxrwx 1 root root 37 May 29 22:34 20-shmop.ini -> /etc/php/7.0/mods-available/shmop.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sockets.ini -> /etc/php/7.0/mods-available/sockets.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sysvmsg.ini -> /etc/php/7.0/mods-available/sysvmsg.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sysvsem.ini -> /etc/php/7.0/mods-available/sysvsem.ini
lrwxrwxrwx 1 root root 39 May 29 22:34 20-sysvshm.ini -> /etc/php/7.0/mods-available/sysvshm.ini
lrwxrwxrwx 1 root root 41 May 29 22:34 20-tokenizer.ini -> /etc/php/7.0/mods-available/tokenizer.ini

/etc/php/7.0/fpm/pool.d:
total 28
drwxr-xr-x 2 root root 4096 May 29 22:34 .
drwxr-xr-x 4 root root 4096 May 29 22:40 ..
-rw-r--r-- 1 root root 18508 May 11 23:12 www.conf

/etc/php/7.0/mods-available:
total 96
drwxr-xr-x 2 root root 4096 May 29 22:34 .
drwxr-xr-x 5 root root 4096 May 29 22:34 ..
-rw-r--r-- 1 root root 74 May 11 23:12 calendar.ini
-rw-r--r-- 1 root root 71 May 11 23:12 ctype.ini
-rw-r--r-- 1 root root 70 May 11 23:12 exif.ini
-rw-r--r-- 1 root root 74 May 11 23:12 fileinfo.ini
-rw-r--r-- 1 root root 69 May 11 23:12 ftp.ini
-rw-r--r-- 1 root root 73 May 11 23:12 gettext.ini
-rw-r--r-- 1 root root 71 May 11 23:12 iconv.ini
-rw-r--r-- 1 root root 68 May 11 23:12 json.ini
-rw-r--r-- 1 root root 76 May 11 23:12 mbstring.ini
-rw-r--r-- 1 root root 79 May 11 23:12 opcache.ini
-rw-r--r-- 1 root root 69 May 11 23:12 pdo.ini
-rw-r--r-- 1 root root 74 May 11 23:12 pdo_pgsql.ini
-rw-r--r-- 1 root root 70 May 11 23:12 pgsql.ini
-rw-r--r-- 1 root root 70 May 11 23:12 phar.ini
-rw-r--r-- 1 root root 71 May 11 23:12 posix.ini
-rw-r--r-- 1 root root 76 May 11 23:12 readline.ini
-rw-r--r-- 1 root root 71 May 11 23:12 shmop.ini
-rw-r--r-- 1 root root 73 May 11 23:12 sockets.ini
-rw-r--r-- 1 root root 73 May 11 23:12 sysvmsg.ini
-rw-r--r-- 1 root root 73 May 11 23:12 sysvsem.ini
-rw-r--r-- 1 root root 73 May 11 23:12 sysvshm.ini
-rw-r--r-- 1 root root 75 May 11 23:12 tokenizer.ini

下面是ps aux的相关流程

root     28217  0.0  2.8 287700 29156 ?        Ss   22:48   0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data 28221 0.0 0.6 287700 7052 ? S 22:48 0:00 php-fpm: pool www
www-data 28222 0.0 0.6 287700 7052 ? S 22:48 0:00 php-fpm: pool www
root 28405 0.0 0.1 124972 1416 ? Ss 23:00 0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 28406 0.0 0.3 125308 3148 ? S 23:00 0:00 nginx: worker process

我以我的名义创建了一个用户,该用户具有 sudo 权限,我正在对它进行实际工作,但我不确定我是否应该为该用户分配权限,或者我是否应该使用 www-data?

最佳答案

此错误已解决——现在返回 404 Not Found,这是预期的行为,因为我还没有将应用程序推送到服务器——通过修改 /etc/nginx/sites 的以下部分——可用/域名

listen 80 default_server;
listen [::]:80 default_server;

修改为

listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

我曾怀疑这可能是问题所在,但确信在我之前遇到这个问题时,我曾尝试过但没有成功。无论如何,我希望这对将来的人有所帮助。

关于Nginx:无法访问该站点;权限配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44251497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com