nginx下载php文件而不是执行它们

我正在尝试设置LEMP堆栈,经过几个教程后我似乎无法获得php 在这里工作是我的nginx配置:</ p>

default.conf:</ p>

  server {
listen 80 0.0.0.0;
listen [ ::]:80 0.0.0.0 ipv6only = on;

#注意这些行最初来自“location /”block
root / usr / share / nginx / html;
index index.php index。 html index.htm;

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;
}

位置〜\ .php $ {
\ try_files $ uri = 404;
fastcgi_split_path_info ^(。+ \。php )(/。+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params; \ n}
}
</ code> </ pre>
</ DIV>

展开原文

原文

I'm trying to set up a LEMP stack and after going through several tutorials i can't seem to get php working here is my nginx config:

default.conf:

server {
    listen   80 0.0.0.0;
    listen   [::]:80 0.0.0.0 ipv6only=on;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    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 ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

duan198123
duan198123 这与cookie完全无关。
接近 2 年之前 回复
duaedf6509
duaedf6509 嗨混乱,尝试清除所有cookie或使用其他浏览器。这种情况发生的时候是常见的解
接近 2 年之前 回复

3个回答

I believe your problem is the second use of try_files inside the PHP block:

location ~ \.php$ {
===>try_files $uri =404;<====
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Just take that line out and try this:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}



你可能需要将它添加到你的位置〜.php $ {}

include snippets / fastcgi- php.conf; </ code>

它看起来应该是这样的:

location~ \ .php $ {
include snippets / fastcgi-php.conf;
... \ n} </ code> </ p>
</ div>

展开原文

原文

You probably need to add this to your location ~ .php$ {}
include snippets/fastcgi-php.conf;
So it should look like:
location ~ \.php$ { include snippets/fastcgi-php.conf; ... }



我发现这个啧啧:</ p>

https://www.linuxbabe.com/linux-server/ 怎么安装-lemp-stack-linux-nginx-mariadb-php-on-centos7 </ p>

它有效!!!!! 现在是我的default.conf:</ p>

  server {
listen 80;
server_name www.example.com example.com;
root / usr / share / nginx / html;
index index.php index.html index.htm;
location / {
try_files $ uri $ uri / /index.php$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root / usr / share / nginx / html;
}
location~ \ .php $ {
try_files $ uri = 404 ;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}
}
</ code> </ pre>
</ div>

展开原文

原文

I found this tut:

https://www.linuxbabe.com/linux-server/how-to-install-lemp-stack-linux-nginx-mariadb-php-on-centos7

It worked!!!!! Here is my default.conf now:

server {
  listen 80;
  server_name www.example.com example.com;
  root /usr/share/nginx/html;
  index index.php index.html index.htm;
  location / {
      try_files $uri $uri/ /index.php$query_string;
  }
  error_page 404 /404.html;
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
      root /usr/share/nginx/html;
  }
  location ~ \.php$ {
      try_files $uri =404;
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
  }
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐