Nginx下载php文件

时间:2018-04-04 05:57:04

标签: php nginx php-7

我有nginx,我想在其中使用php。我的域名是example.com,我在/etc/nginx/conf.d/example.com中有一个此域的配置文件,这是它的配置文件:

server {
    listen 80;
    server_name example.com;
    location / {
        root /home/emad/website;
    }

    location /nrm {
        rewrite ^/nrm/(.*)$ /$1 break;
        proxy_pass http://127.0.0.1:4646;
    }

    location /files/khu {
        rewrite ^/files/khu/(.*)$ files/khu/$1 break;
        proxy_pass http://127.0.0.1:8000;
    }

    location /files {
        rewrite ^/files/(.*)$ files/$1 break;
        proxy_pass http://127.0.0.1:8000;
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
}

我更改了提供php文件的默认配置文件,如this

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /home/emad/website;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/emad/website$fastcgi_script_name;
        include         fastcgi_params;
    }
    location ~ /\.ht {
            deny all;
    }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#} 

我不知道在这一行中应该用SCRIPT_FILENAME代替什么:

fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; 这也是我的/etc/rc.local文件:

#!/bin/sh -e
iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -I FORWARD -s 10.8.0.0/24 -j ACCEPT
iptables -I INPUT -p udp --dport 1194 -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to 138.201.178.5
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php-cgi7.0 -P /var/run/fastcgi-php.pid
exit 0

我已启用utfw,现在我可以正确查看我的网站第一页,但是当我输入example.com/info.php我的浏览器下载php文件时。我也清除了我的浏览器缓存。

0 个答案:

没有答案