我对NGINX比较陌生,我承认(不到24小时),但是,我基本配置了它。我正在为朋友设置一个网站,我看到了一些使用子域的代码示例,如下面的代码所示。但是,在子域中,PHP将无法工作。它只是要求我下载文件,如果我去“subdomain.domain.tld”,但是,如果我去“subdomain.domain.tld / index.php”,它会说“没有指定输入文件。”顺便说一句,子域名是phpmyadmin。
server {
listen 80;
server_name irc.physibots.info;
rewrite (.*) http://physibots.info:3989;
}
server {
listen 80;
server_name "~^([a-z]+)?.physibots.info";
root /home/virtual/physibots.info/subdomains/$1;
index index.php index.html index.html;
location / {
autoindex on;
}
location ~ \.php {
try_files $uri /error.html
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
include fastcgi_params;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
#server {
# listen 443;
# server_name localhost;
#
# charset utf-8;
#
# ssl on;
# ssl_certificate
server {
listen 80;
server_name physibots.info default;
root /home/virtual/physibots.info/public_html;
index index.php index.html index.html;
location / {
autoindex on;
}
location ~ \.php {
try_files $uri /error.html
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
include fastcgi_params;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
答案 0 :(得分:2)
将try_files移动到您的位置/ {}块并将其更改为try_files $ uri $ uri / /index.php;
location / {
autoindex on;
try_files $uri $uri/ /index.php;
}
location ~ \.php {
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php.socket;
对于初学者来说,其余的看起来非常好。 :)
此外 - 确保您使用curl进行测试,而不是使用网络浏览器进行测试,否则您将不断对抗缓存。