这是过去两天的一场斗争。我做了很多搜索,找不到任何解决办法。Nginx PHP页面下载而不是显示
这里是我的nginx.conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
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;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# 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/*;
}
这里是在/ etc/nginx的/我的默认文件站点启用-:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html/;
index index.php index.html index.htm;
server_name [redacted server IP];
location/{
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ /admin/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
将网页存储在/ usr /共享/ nginx的/ html/admin/index.php - 它提示输入用户名/密码(工作正常),但只要我登录,它就会下载而不是显示php网页。
如果我把'location〜/ admin /'块放在'location〜.php $'块之后,它可以工作,但是不会进行验证。
我在另一个文件夹中编写的脚本在调用'/usr/share/nginx/html/api/XXX.php'文件夹时会正常工作(它将插入到MySQL数据库中),但它只是返回JSON的东西。
你对我的帮助很大,我真的很感激。
取消注释1行,它将起作用。 – r3wt 2014-12-03 20:47:35
@ r3wt我试过了,没有运气。我将更改帖子中的代码以显示 – Skull1234567 2014-12-03 21:10:54