ubuntu - 如何更改 nginx 文档根目录以指向 ubuntu 20.10 中不同分区中的文件夹?
问题描述
要更改 nginx 文档根目录,我采取了以下步骤:
文件:/etc/nginx/sites-available/default
# root /var/www/html # commented this line
root /media/{user}/DATA/www # this change give " 404 not found " when i visit '127.0.0.1'
root /home/{user}/www # this works fine when i visit '127.0.0.1'
所以,当我将文档根目录更改为放置在不同分区中的文件夹时,它会给我“404 not found”
还有什么我必须改变的,将文档根指向放置在不同分区中的文件夹吗?
整个文件:/etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
# root /var/www/html;
root /home/sndp/www;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
# With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
编辑:
当我检查错误日志时出现错误:
2021/03/14 15:58:17 [crit] 24648#24648: *1 stat() "/media/sndp/DATA/www/" failed (13: Permission denied), client: ::1, server: _, request: "GET / HTTP/1.1", host: "localhost"
但两个目录的权限相同。
权限:
❯ ls -al /home/sndp/www/
drwxrwxr-x 5 sndp sndp 4096 Mar 14 15:32 .
drwxr-xr-x 25 sndp sndp 4096 Mar 13 12:39 ..
-rwxr-xr-x 1 www-data www-data 17 Mar 13 13:47 index.php
❯ ls -al /media/sndp/DATA/www/
drwxrwxr-x 2 sndp sndp 4096 Mar 14 15:57 .
drwxrwxr-x 8 sndp sndp 4096 Mar 14 15:57 ..
-rwxr-xr-x 1 www-data www-data 17 Mar 13 13:47 index.php
解决方案
推荐阅读
- python-3.x - 哈希(SHA2 -256)Apache Nifi 中 Avro 文件中的列(作为流文件出现)
- excel - 将代码从工作表/模块传输到 VBA 中的用户窗体
- racket - 使用循环携带依赖简化循环
- css - 无法居中按钮
- javascript - 选中复选框时,acrobat javascript,需要单独的字段
- c++ - 如何使用 GMock 的 Field() 宏来匹配结构/联合的嵌套成员?
- geoserver - 在地理服务器中找不到 imagepyramid 的 sample_image
- azure - Azure CI/CD - Azure 私有 Npm 注册表 - 无法进行身份验证,需要:Bearer authorization_uri=https://login.windows.net
- perl - 有没有办法设置 XML::LibXML->load_html(location => $url) 的连接超时
- jmeter - 我创建了一个由 10 个用户组成的步进线程组,但在运行计划后它没有显示用户数,也没有停止在 10 个用户