我正在尝试建立一个LEMP堆栈,并且在完成了一些教程之后,我似乎无法在这里使用php作为我的nginx配置:
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;
}
}
答案 0 :(得分:0)
我相信您的问题是try_files
在PHP块中的第二次使用:
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;
}
只需将该行删掉,然后尝试以下操作即可:
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;
}
答案 1 :(得分:0)
您可能需要将此添加到您的位置〜.php $ {}
#include<iostream>
using namespace std;
int& f(int&);
int& g(int& i)
{
cout << " i " << i;
if(i>0)
{
int& j = i;
i = f(j)-1;
cout << " j " << j << "->f->";
return j;
}
return i;
}
int& f(int& i)
{
cout << " i " << i;
if(i>0)
{
int& j = i;
j--;
i = g(j);
cout << " j " << j << "->g->";
return j;
}
return i;
}
int main(void)
{
int i = 10;
f(i);
cout << "-->> finally " << i << endl;
return 0;
}
看起来应该像这样:
include snippets/fastcgi-php.conf;
答案 2 :(得分:0)
我找到了这个孩子:
https://www.linuxbabe.com/linux-server/how-to-install-lemp-stack-linux-nginx-mariadb-php-on-centos7
成功了!!!!现在是我的default.conf:
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;
}
}