2015-06-22 300 views
0

我正在尝试为项目构建一个小型CMS。部分原因是,当您点击save-button时,您当前的编辑将被保存。Ajax post在localhost上运行,但在nginx服务器上运行

$('.save-button').click(function() { 

    var speisekarte_content = $(".speisekarte-content").html(); 
    console.log(speisekarte_content); 
    var ajaxurl = 'save.php', 
    data = { 
     'content': speisekarte_content 
    }; 
    $.post(ajaxurl, data, function(response) { 
    alert("action performed successfully"); 
    }); 

}); 

的save.php看起来是这样的:

<?php 

$post_data = $_POST['content']; 

if (function_exists('fopen')) { 
    if (!empty($post_data)) { 
     $filename = 'speisekarte-content.php'; 
     $handle = fopen($filename, "w"); 
     fwrite($handle, $post_data); 
     fclose($handle); 
     echo $file; 
    } 
}; 

?> 

因此,它基本上只是补充说,应该被保存到一个名为speisekarte-content.php文件中的内容。这工作完全在本地主机上 - 直到我将它上传到我的nginx服务器,并且按照设想停止工作。 这是错误日志,我在JavaScript控制台中发现:

POST 
http://www.myurl.com/editable/save.php net::ERR_TIMED_OUT 

k.cors.a.crossDomain.send @ jquery.min.js:4 
n.extend.ajax @ jquery.min.js:4 
n.(anonymous function) @ jquery.min.js:4 
(anonymous function) @ main.js:99 

nginx的错误日志以下

2015/06/22 08:43:45 [error] 6804#0: *63817 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: content in /var/www/myurl.com/html/editable/save.php on line 2 
PHP message: PHP Warning: fopen(autosave.php): failed to open stream: Permission denied in /var/www/myurl.com/html/editable/save.php on line 27 
PHP message: PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/myurl.com/html/editable/save.php on line 28 
PHP message: PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/myurl.com/html/editable/save.php on line 29 
PHP message: PHP Notice: Undefined variable: file in /var/www/myurl.com/html/editable/save.php on line 30" while reading response header from upstream, client: 176.0.1.54, server: myurl.com, request: "POST /editable/save.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.myurl.com", referrer: "http://www.myurl.com/editable/" 

是nginx的或我的代码这有关系吗?

+0

'console'不得不说什么? – Tushar

+0

@Daan它允许在一行中设置两个变量。 Retador,你有没有检查文件权限,htacess等? –

+0

@Tushar我在那里发布了错误日志......否则它会记录我的div与speisekarte-content'类的内容:) – Retador

回答

0

你的日志说,你的应用程序没有在他目前进驻书写的权利。 你应该检查你的文件的权利 你可以在应用程序的文件夹中发布ls -al的输出吗?

+0

好吧,我把输出的piratepad文件:http://piratepad.net/ep/pad/view/ro.tHwqX$uuO1T/latest – Retador

+0

您的所有文件都属于为根,所以我想包含它的文件夹。 如果所有者为root,则Nginx无法创建文件,您必须更改包含您的应用的文件夹的所有者或组 – jbduzan

+0

哦,以及我应该更改哪个所有者?只是一个随机的?我认为根将是“超级用户”,它可以执行基本上任何行动 – Retador

相关问题