将Nginx索引文件移至/home目录时出现403/404错误求助
树莓派Nginx部署问题:主目录静态文件访问异常
首次在树莓派部署Nginx服务器,笔记本与树莓派处于同一WiFi网络,可通过树莓派IP访问默认页面。希望将静态文件放在个人主目录/home/pi-simon/html下,但访问出现权限或404错误,寻求解决。
已尝试的操作
- 通过
apt install nginx完成安装,默认页面可正常访问; - 将默认页面
index.nginx-debian.html复制到/home/pi-simon/html,修改/etc/nginx/sites-available/default配置后访问出现403 Forbidden,配置内容如下:
server { listen 80 default_server; listen [::]:80 default_server; server_name _; location / { # root /var/www/html; root /home/pi-simon/html; index index.html index.nginx-debian.html; try_files $uri $uri/ =404; } }
- 调整
index.nginx-debian.html存放位置并同步修改配置后,访问结果如下:
index.nginx-debian.html存放位置 | 访问http://raspberrypi.local/结果 |
|---|---|
/var/www/html | 正常访问 |
/home | 正常访问 |
/home/pi-simon | 403 Forbidden |
/home/pi-simon/html | 404 Not Found |
- 调整过文件及目录的所属用户/组为
www-data,问题未解决; - 修改
try_files $uri $uri/ =404;规则,仅会在403和404错误间切换; - 每次修改配置后均执行
systemctl restart nginx重启服务,确认无拼写错误。
当前nginx.conf配置
user www-data; worker_processes auto; pid /run/nginx.pid; error_log /var/log/nginx/error.log; include /etc/nginx/modules-enabled/*.conf; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # SSL Settings ## ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE ssl_prefer_server_ciphers on; ## # Logging Settings ## access_log /var/log/nginx/access.log; ## # Gzip Settings ## gzip on; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; # gzip_buffers 16 8k; # gzip_http_version 1.1; # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; # server { # listen 8080; # root /data/up1; # # location / { # } # } } #mail { # # See sample authentication script at: # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript # # # auth_http localhost/auth.php; # # pop3_capabilities "TOP" "USER"; # # imap_capabilities "IMAP4rev1" "UIDPLUS"; # # server { # listen localhost:110; # protocol pop3; # proxy on; # } # # server { # listen localhost:143; # protocol imap; # proxy on; # } #}
内容的提问来源于stack exchange,提问作者simon
相关产品推荐
相关产品推荐

