我尝试使用nginx提供PHP服务,我之前已成功关注this tutorial但出于某种原因在新服务器上出现以下错误:
nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory)
实际上,缺少nginx安装的整个snippets
目录。
我已使用以下命令安装PHP:
- sudo apt-get install -y php7.0-cli php7.0-cgi php-fpm php-mysql
- sudo systemctl restart php7.0-fpm
我已安装了最新的nginx,但目录和文件仍然不存在。
如何解决这个问题?
奖金:可能导致这种情况的原因是什么?
答案 0 :(得分:16)
我认为这取决于您使用的Nginx版本。
对于Nate的回答,nginx-full
将为您安装1.10.3。
我在Ubuntu 16.04上使用Nginx 1.12.2,对于这个版本,它没有sites-enabled
和sites-available
。它也有不同的PHP CGI设置。
您可以使用Ulad Kasach的解决方案,也可以开始使用新方式。
以下是有关如何操作的官方文档:https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
顺便说一句,在上面的帖子中,您还应该将fastcgi.conf
替换为fastcgi_params
。
再添加一行,默认为orignially:
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
这些都是Nginx 1.12.2的新变化:(
最终版本是:
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
答案 1 :(得分:4)
完成必须查看以前的工作配置文件并手动复制它。只需创建snippets
目录并添加一个fastcgi-php.conf
文件,其中包含以下内容:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
您还需要将最后一行include fastcgi.conf;
替换为include fastcgi_params;
。
如果fastcgi.conf;
答案 2 :(得分:4)
我也难过了一会儿。您想在ubuntu上安装nginx-full
包而不是nginx
。 nginx-full
包含您缺少的部分。
答案 3 :(得分:1)
我正在使用
我的网站配置如下
class App extends Component {
constructor() {
super();
this.state = {checked: false}}
onCheck = () => {
const { checked } = this.state;
if(checked == true){this.setState({ checked: false }) }
else {this.setState({ checked: true })}}
render() {
return (
<FlatList
data = {[
{firstName:'User_A',},
{firstName:'User_B',},
{firstName:'User_C',},
{firstName:'User_D',},
{firstName:'User_E',},
]}
renderItem = {({item}) =>
<TouchableOpacity onPress={() => { this.onCheck() }} activeOpacity = {0.5}>
<View style = {{flexDirection : 'row'}}>
<Left>
<Radio selected = {this.state.checked}/>
</Left>
<Card style = {{marginRight : 100, height : 50}}>
<View>
<View>
<Text> {item.firstName} </Text>
</View>
</Card>
</View>
</TouchableOpacity>
}
/>
)
}
并且运行良好。 所以我建议您更新您的 配置 包括摘要/fastcgi-php.conf; 到
包括fastcgi_params;
所以位置块是
server {
listen 3010;
root /usr/share/nginx/docs;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name phpSetup;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
希望能帮助
进一步了解: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
谢谢