我今天运气真不好。我不知道是怎么回事,但是我无法让 NGINX 做它应该做的事。
我想要实现以下目标:
domain.com shows index.html (/var/www/domain/index.html)
domain.com/upload (also domain.com/upload/) shows upload.php (/var/www/domain/upload.php)
仅提供 index.html 没有问题。但是,我遇到了/上传部分。
我尝试使用location /upload
和,location = /upload
但运气不佳。有一次,我让它工作了,但马上就放弃了,因为 php 文件正在下载但无法提供服务。
如果您能告诉我我的服务器块到底应该是什么样子,我将不胜感激。
答案1
server {
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name www.example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log debug;
root /var/www/domain/;
index index.php index.html;
location /static {
try_files $uri $uri/ @php_index =404;
}
location / {
try_files $uri $uri/ $uri/index.html $uri/index.htm @php;
}
location @php {
try_files $uri /index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
}
location ~ \.php$ {
try_files $uri /index.php =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
}
}