Ape*_*ron 128 php nginx php-5.5
我正在一个小滴(数字海洋)安装一个网站.我有一个问题,正确安装NGINX与PHP.我做了一个教程https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04但是当我尝试运行一些.php文件它只是下载它...例如...... http://5.101.99.123/info.php
它正在工作但是......如果我去主要http://5.101.99.123
它下载我的index.php:/
任何的想法?
-rw-r--r-- 1 agitar_user www-data 418 Jul 31 18:27 index.php
-rw-r--r-- 1 agitar_user www-data 21 Aug 31 11:20 info.php
Run Code Online (Sandbox Code Playgroud)
我的/ etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name agitarycompartir.com;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
Run Code Online (Sandbox Code Playgroud)
...其他"位置"被评论(#)
Jac*_* M. 119
试试这个:
/etc/nginx/sites-available/default
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default_server ipv6only=on; ## listen for ipv6
Run Code Online (Sandbox Code Playgroud)server_name
独自# Make site accessible (...)
server_name localhost;
Run Code Online (Sandbox Code Playgroud)index.php
到该index
行root /usr/share/nginx/www;
index index.php index.html index.htm;
Run Code Online (Sandbox Code Playgroud)location ~ \.php$ {}
# pass the PHP scripts to FastCGI server listening on (...)
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)/etc/php5/fpm/php.ini
并确保cgi.fix_pathinfo
设置为0
我一周前刚刚开始使用Linux,所以我真的希望能帮到你.我正在使用nano文本编辑器来编辑文件.如果没有,请运行apt-get install nano.谷歌就此了解更多.
小智 42
您需要将此添加到/ etc/nginx/sites-enabled/default以在Nginx Server上执行php文件:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
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;
}
}
Run Code Online (Sandbox Code Playgroud)
np8*_*np8 34
我有类似的问题,通过清空浏览器缓存解决(也适用于不同的浏览器).
M A*_*fan 12
更新nginx config/etc/nginx/sites-available/default或您的配置文件
如果你使用php7使用这个
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
Run Code Online (Sandbox Code Playgroud)
如果你使用php5使用这个
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)
访问这里获取完整的详细信息
小智 8
我有同样的问题,没有一个答案解决了这个问题.
我跑了:
sudo nginx -t
Run Code Online (Sandbox Code Playgroud)
在/ etc/nginx/sites-available/default测试配置文件.
它给了我这些错误:
nginx: [emerg] unexpected end of file, expecting "}" in /etc/nginx/sites-enabled/default:115
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
所以我进入配置文件,最后一行是
#}
Run Code Online (Sandbox Code Playgroud)
我取消注释,再次运行测试命令,它工作
小智 7
这适合我.
1)MyApp文件
vi/etc/nginx/sites-available/myApp
server {
listen 80;
listen [::]:80;
root /var/www/myApp;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Run Code Online (Sandbox Code Playgroud)
PHP5用户
更改
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
Run Code Online (Sandbox Code Playgroud)
至
fastcgi_pass unix:/var/run/php5-fpm.sock;
Run Code Online (Sandbox Code Playgroud)
2)配置cgi.fix_pathinfo
将cgi.fix_pathinfo设置为0
地点:
PHP5 /etc/php5/fpm/php.ini
PHP7 /etc/php/7.0/fpm/php.ini
3)重启服务
FPM
PHP5 sudo service php5-fpm restart
PHP7 sudo service php7.0-fpm restart
NGINX
sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)
我在上面看到了很多解决方案,许多解决方案对我来说都是正确的,但是我不明白他们在做什么,并且担心只复制粘贴代码,尤其是fastcgi。这是我的2美分
对于某些服务器(例如Apache),内置了解释PHP的支持,因此不需要CGI。
这个数字海洋链接,很好地解释了安装FPM的步骤,并且我没有编写解决php文件下载而不是渲染的问题所需的步骤,因为其他答案我都很好。
For me it helped to add ?$query_string
at the end of /index.php, like below:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
Run Code Online (Sandbox Code Playgroud)
在 php7.2 的情况下,上面的片段对我有用
归档时间: |
|
查看次数: |
213153 次 |
最近记录: |