我在Amazon AWS上使用我的nginx webserver發生此問題。Jquery在nginx上調用php,不起作用
首先,這段代碼正在另一臺服務器上工作和測試,但我需要遷移到我自己的服務器,這裏是我遇到問題的地方。 我有以下的jQuery + PHP代碼或HTML頁面,它不是正在執行這樣的事情:
<div class="widget widget-twitter-feed clearfix">
<h4>Twitter Feed</h4>
<ul id="sidebar-twitter-list-1" class="iconlist">
<li></li>
</ul>
<a href="https://twitter.com/coinnova_ok" class="btn btn-default btn-sm fright">Follow Us on Twitter</a>
<script type="text/javascript">
jQuery(function($){
$.getJSON('include/twitter/tweets.php?username=coinnova_ok', function(tweets){
$("#sidebar-twitter-list-1").html(sm_format_twitter(tweets));
});
});
</script>
這是我的虛擬主機配置上的nginx:
server {
listen 80;
server_name localhost;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.html$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.htm;
include fastcgi.conf;
}
location ~ \.js$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
我也更改這些我/etc/php-fpm.d/www.conf設置
security.limit_extensions = .php .html .js
我希望有人能幫助我:)
更多信息
這是需要執行的tweets.php腳本。我想補充它只是供參考,但它在另一臺服務器上,以及:
<?php
session_start();
if(isset($_GET['username']) AND $_GET['username'] != ''):
require_once('oauth/twitteroauth.php'); //Path to twitteroauth library
$username = $_GET['username'];
$limit = (isset($_GET['count']) AND $_GET['count'] != '') ? $_GET['count'] : 2;
$consumerkey = "LAxZjcBtFOw1wYhJ2Tqm8w";
$consumersecret = "0SyeOk44o70ya2EVweHgJtwqBkr6DaoO0CETToFKsI";
$accesstoken = "329620819-0tbQsQ7yx9BV5E6SzPaP39UAlDBuUokwRqgw075H";
$accesstokensecret = "iL0divFR8xjTWQj9de511YxBpKkduE8dcOCRRlMrM";
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
$interval = 600;
$cache_file = dirname(__FILE__) . '/cache/' . $username . '_' . $limit;
if (file_exists($cache_file)) {
$last = filemtime($cache_file);
} else { $last = false; }
$now = time();
if (!$last || (($now - $last) > $interval)) {
$context = stream_context_create(array(
'http' => array(
'timeout' => 3
)
));
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$twitter_feed = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$username."&count=".$limit);
$cache_rss = serialize($twitter_feed);
if (!empty($cache_rss)) {
$cache_static = fopen($cache_file, 'wb');
fwrite($cache_static, $cache_rss);
fclose($cache_static);
}
$rss = @unserialize(file_get_contents($cache_file));
} else {
$rss = @unserialize(file_get_contents($cache_file));
}
echo json_encode($rss);
endif;
?>
你是什麼意思下,「它沒有被執行」? – ankhzet
嗨!,它是一個Twitter的飼料,它的起源是從特定的Twitter帳戶中檢索推文,但它不工作,推文沒有顯示..我有這個小工具在另一臺服務器上工作,但它不是我的,我不能看到conf。 –
您應該提供您遇到的錯誤消息,如果有的話。就像當你用這個腳本打開頁面一樣,在錯誤控制檯中顯示什麼錯誤?它是否抱怨位置爲'include/twitter/tweets.php?username = coinnova_ok'的未提供腳本?在文檔根目錄下放置在你的nginx服務器上的'include/twitter /'位置? – ankhzet