谢谢你的答案@ r3wt。但是,我猜上面的配置文件是不合适的我不想保持原样(但是对于我来说开发似乎没问题,因为部署我宁愿为每个站点使用单独的配置文件)。
所以,别名部分和我的问题应该正确定义try_files因为我想要捕获链接以localhost / szpetra开头所以我添加它并取消注释别名部分因为现在我清楚地了解root和别名whis之间的区别是什么是:
This will result in files being searched for in /foo/bar/bar as the full URI is appended.
location /bar {
root /foo/bar;
}
This will result in files being searched for in /foo/bar as only the URI part after /bar is appended.
location /bar {
alias /foo/bar;
}
资料来源:https://forum.nginx.org/read.php?2,129656,130107
现在修改后的配置文件如下所示:
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost-access_log main;
error_log /var/log/nginx/localhost-error_log info;
root /var/www/localhost/htdocs/;
index index.php index.html index.htm; # I used index definition here so I think I shouldn't define it under a 'location' field.
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi.conf;
fastcgi_pass unix:run/php-fpm.socket;
}
location /phpmyadmin {
alias /var/www/localhost/htdocs/phpmyadmin;
access_log /var/log/nginx/phpmyadmin-access_log main;
error_log /var/log/nginx/phpmyadmin-error_log info;
}
location /samplewordpress {
alias /var/www/localhost/htdocs/samplewordpress;
access_log /var/log/nginx/samplewordpress-access_log main;
error_log /var/log/nginx/samplewordpress-error_log info;
}
location /szpetra {
# alias /var/www/localhost/htdocs/szpetra; #uncommenting alias helped me solve the problem
access_log /var/log/nginx/szpetra-access_log main;
error_log /var/log/nginx/szpetra-error_log info;
# index index.php index.html index.htm; # this doesn't need cause I defined the indexes above in the server{} section but I'm not sure that about this
try_files $uri $uri/ /szpetra/index.php?$args; # Adding this line helped me solve the problem
}}