当我访问我的应用的某个网址时,我的目标是看到类似的内容:
location /backup {
autoindex on;
index index.html;
root /home/app/public/backup;
}
我的整个vi /etc/nginx/sites-available/default
server {
listen 80 default_server;
server_name default;
root /home/app/public;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
location /backup {
autoindex on;
index index.html;
root /home/app/public/backup;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
答案 0 :(得分:3)
根据您的配置,nginx
正在尝试找到/home/app/public/backup/backup
路径,因此404
。
这三种解决方案适合您
# remove root directive (recommended in your case)
location /backup {
autoindex on;
index index.html;
#root /home/app/public/backup;
}
# set root to public (redundant since already done)
location /backup {
autoindex on;
index index.html;
root /home/app/public;
}
# replace root with alias
location /backup {
autoindex on;
index index.html;
alias /home/app/public/backup;
}
有关详情,请查看root
和alias
的工作原理,您还可以阅读nginx
handles user requests