Have Nginx As Backend
Have Nginx As Backend
Hey Guys
I wanted to inquire if there was a way rather than having apache as backend and nginx as front end. We can have full nginx ie backend as well as frontend, Currently i am using phpfcgid but the script that i am running requires some modules to run as nginx rather than apache.
It would be great if someone could help me out here
Thanks
I wanted to inquire if there was a way rather than having apache as backend and nginx as front end. We can have full nginx ie backend as well as frontend, Currently i am using phpfcgid but the script that i am running requires some modules to run as nginx rather than apache.
It would be great if someone could help me out here
Thanks
Re: Have Nginx As Backend
How so? Can you show some examples may be?msk19994 wrote:but the script that i am running requires some modules to run as nginx rather than apache
Re: Have Nginx As Backend
In this thread i inquired to add some additional code to nginx http://forum.vestacp.com/viewtopic.php?f=11&t=12165
after doing that the nginx is working no errors but the code itself is not working
This is what i am trying to accomplish

the table plugin_reward_ppd_complete_download is empty and not updating

Below is the log download file code
after doing that the nginx is working no errors but the code itself is not working
This is what i am trying to accomplish

the table plugin_reward_ppd_complete_download is empty and not updating

Below is the log download file code
Code: Select all
<?php
// used for NGINX callback on PPD download finish. See the admin area, reward
// plugin settings for more information.
// global includes
define('CLI_MODE', true);
require_once('../../../core/includes/master.inc.php');
// log callback data
log::setContext('plugin_reward_nginx_complete_download');
log::breakInLogFile();
log::info('Data received: ' . http_build_query($_REQUEST));
// ignore if not OK response
//if ((!isset($_REQUEST['status'])) || ((strtoupper($_REQUEST['status']) != 'OK') && (strtoupper($_REQUEST['status']) != '')))
if ((!isset($_REQUEST['status'])) || ((strtoupper($_REQUEST['status']) != 'OK')))
{
//log::info('No status found or status not \'OK\'');
//exit;
}
// prepare response for inserting
$downloadTokenExp = explode('download_token=', $_REQUEST['request_uri']);
$downloadToken = current(explode('&', $downloadTokenExp[1]));
if (!strlen($downloadToken))
{
log::info('No download token found.');
exit;
}
// initial variables
$payPPD = false;
// load file details
$fileSize = -1;
$fileUserId = NULL;
$fileId = -1;
$fileDetail = $db->getRow('SELECT file.fileSize, file.userId, file.id FROM file LEFT JOIN download_token ON file.id = download_token.file_id WHERE download_token.token=' . $db->quote($downloadToken) . ' LIMIT 1');
if (!$fileDetail)
{
log::info('Could not load download token details using '.$downloadToken);
exit;
}
$fileSize = $fileDetail['fileSize'];
$fileUserId = $fileDetail['userId'];
$fileId = $fileDetail['id'];
// if total bytes sent equals file size pay PPD
if(strlen($_REQUEST['body_bytes_sent']) && ($fileSize == $_REQUEST['body_bytes_sent']))
{
log::info('Filesize downloaded ('.$_REQUEST['body_bytes_sent'].') matches actual filesize ('.$fileSize.'). Non chunked.');
$payPPD = true;
}
// log in database
//$payPPD = true;
$dbInsert = new DBObject("plugin_reward_ppd_complete_download", array("download_token", "date_added", "download_ip", "bytes_sent", "pay_ppd"));
$dbInsert->download_token = $downloadToken;
$dbInsert->date_added = coreFunctions::sqlDateTime();
$dbInsert->download_ip = $_REQUEST['remote_addr'];
if(strlen($_REQUEST['body_bytes_sent']))
{
$dbInsert->bytes_sent = $_REQUEST['body_bytes_sent'];
}
else
{
$dbInsert->bytes_sent = 0;
}
$dbInsert->pay_ppd = (int) $payPPD;
$rowId = $dbInsert->insert();
// lookup for partial completed downloads for this token, required in later versions of Nginx
if ($payPPD == false)
{
$totalDownloadedSize = $db->getValue('SELECT SUM(plugin_reward_ppd_complete_download.bytes_sent) AS total FROM plugin_reward_ppd_complete_download WHERE download_token=' . $db->quote($downloadToken) . ' AND pay_ppd=0');
if ($totalDownloadedSize >= $fileSize)
{
log::info('Total filesize downloaded ('.$totalDownloadedSize.') is greater than or matches actual filesize ('.$fileSize.'). Chunked, so total sum of bytes sent.');
$payPPD = true;
}
}
if ($payPPD == true)
{
// check owner isn't the person downloading it, we don't log PPD payments
$userDetail = $db->getRow('SELECT users.username, users.level_id AS package_id, users.id FROM users LEFT JOIN download_token ON users.id = download_token.user_id WHERE download_token.token=' . $db->quote($downloadToken) . ' LIMIT 1');
if ($userDetail)
{
$tokenUsername = $userDetail['username'];
$tokenLevelId = UserPeer::getLevelIdFromPackageId($userDetail['package_id']);
$tokenUserId = $userDetail['id'];
// check downloader against file owner
if ($tokenUserId == $fileUserId)
{
// log
log::info('No PPD logged as downloaded by file owner.');
$payPPD = false;
}
elseif ($tokenLevelId >= 20)
{
// log
log::info('No PPD logged as downloaded by admin user.');
$payPPD = false;
}
}
}
// update older records to set paid
if ($payPPD == true)
{
$db->query('UPDATE plugin_reward_ppd_complete_download SET pay_ppd=1 WHERE pay_ppd=0 AND download_token=' . $db->quote($downloadToken));
}
// log PPD if not file owner
if ($payPPD)
{
// log
log::info('Total file downloaded, logging PPD.');
// rebuild plugin cache, needed as 'server' session caches plugin data so any plugin config changes are not applied
pluginHelper::loadPluginConfigurationFiles(true);
// include download complete process to actually log the PPD
pluginHelper::includeAppends('class_file_download_complete.php', array('origin' => '_log_download.php', 'forceDownload' => true, 'fileOwnerUserId' => $tokenUserId, 'userLevelId' => $tokenLevelId, 'file' => file::loadById($fileId), 'doPluginIncludes' => false, 'ipOverride'=>$_REQUEST['remote_addr']));
}
Re: Have Nginx As Backend
It's not nginx your backend, nginx still your front-end. Your backend here - php-fpm or something like this.
Nginx can't be backend by yourself for dynamic content (can if you server static content only: html/files/etc).
Nginx can't be backend by yourself for dynamic content (can if you server static content only: html/files/etc).
Re: Have Nginx As Backend
Like you had suggested i have installed nginx + php-fpm
Now i am having a similar issue when adding code to the nginx file
Now for the site to work i had to add some codes
I added
and others but now when i need to add this new module and replace this old code
i have to add
after replacing it says
when added command
Now i am having a similar issue when adding code to the nginx file
Code: Select all
server {
listen 158.69.223.8:80;
server_name picu.pk www.picu.pk;
root /home/admin/web/picu.pk/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/picu.pk.log combined;
access_log /var/log/nginx/domains/picu.pk.bytes bytes;
error_log /var/log/nginx/domains/picu.pk.error.log error;
location / {
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/admin/web/picu.pk/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/nginx.picu.pk.conf*;
}
server {
listen 158.69.5.207:80;
server_name hostingrill.co www.hostingrill.co;
root /home/admin/web/hostingrill.co/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/hostingrill.co.log combined;
access_log /var/log/nginx/domains/hostingrill.co.bytes bytes;
error_log /var/log/nginx/domains/hostingrill.co.error.log error;
location / {
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
}
location / {
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?_page_url=$1 last;
}
}
location /files/ {
internal;
}
# these locations would be hidden by .htaccess normally
location /core/logs/ {
deny all;
}
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/admin/web/hostingrill.co/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/nginx.hostingrill.co.conf*;
}
I added
Code: Select all
location /files/ {
internal;
}
i have to add
Code: Select all
location /files {
root /home/admin/web/hostingrill.co/public_html;
post_action @afterdownload;
internal;
}
location @afterdownload {
proxy_pass http://hostingrill.co/plugins/rewards/site/_log_download.php?request_uri=$request_uri&remote_addr=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion&content_length=$content_length&http_user_agent=$http_user_agent&http_referer=$http_referer&args=$args;
internal;
}
when added command
Code: Select all
nginx -t
nginx: [emerg] named location "@afterdownload" can be on the server level only in /home/admin/conf/web/nginx.conf:93
nginx: configuration file /etc/nginx/nginx.conf test failed
Re: Have Nginx As Backend
Code: Select all
proxy_pass http://hostingrill.co/plugins/rewards/site/_log_download.php?request_uri=$request_uri&remote_addr=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion&content_length=$content_length&http_user_agent=$http_user_agent&http_referer=$http_referer&args=$args;
Let php-fpm do the thing.. try to use default template and change for yourself just in case it's needed.
Re: Have Nginx As Backend
I think something like this may work:
code hereShow
Code: Select all
server {
listen 158.69.5.207:80;
server_name hostingrill.co www.hostingrill.co;
root /home/admin/web/hostingrill.co/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/hostingrill.co.log combined;
access_log /var/log/nginx/domains/hostingrill.co.bytes bytes;
error_log /var/log/nginx/domains/hostingrill.co.error.log error;
client_max_body_size 5G;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
fastcgi_pass 127.0.0.1:9002;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
if (!-e $request_filename) {
rewrite ^/(.*) /index.php?_page_url=$1 last;
}
}
location /files/ {
root /home/admin/web/hostingrill.co/public_html;
post_action @afterdownload;
internal;
}
location @afterdownload {
proxy_pass http://hostingrill.co/plugins/rewards/site/_log_download.php?request_uri=$request_uri&remote_addr=$remote_addr&body_bytes_sent=$body_bytes_sent&status=$request_completion&content_length=$content_length&http_user_agent=$http_user_agent&http_referer=$http_referer&args=$args;
internal;
}
# these locations would be hidden by .htaccess normally
location /core/logs/ {
deny all;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location /error/ {
alias /home/admin/web/hostingrill.co/document_errors/;
}
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
include /etc/nginx/conf.d/phpmyadmin.inc*;
include /etc/nginx/conf.d/phppgadmin.inc*;
include /etc/nginx/conf.d/webmail.inc*;
include /home/admin/conf/web/nginx.hostingrill.co.conf*;
}