PHP File upload to NGINX & PHP5-FPM - codeigniter

I am uploading a file to my server and getting the following log, and after a lot of googling I cannot find an answer can any one help or suggest where to start?
2014/06/26 17:15:01 [error] 15035#0: *2491 FastCGI sent in stderr:
"PHP message: height: 375 - width: 600" while reading response header
from upstream, client: , server: url, request: "POST
/user/updateProfile HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000",
host: "url", referrer: "url/user/edit/7"
I have hidden the url's for security purposes.
Thanks!
EDIT *
PHP code for upload
if(empty($_FILES['user_cover_image_url']['name'])) {
} else {
//Cover Elements
$coverName = $_FILES['user_cover_image_url']['name'];
$coverExtension=end(explode(".", $coverName));
if($coverExtension=='png') {$coverExtension = 'jpg';}
$cName = $uid.'-'.$pass->generateRandomString($length=25);
$coverImage = $cName.'.'.$coverExtension;
$cSource = $_FILES['user_cover_image_url']['tmp_name'];
$cDestination = '/var/www/html/tmp/cover-'.uniqid().'.'.$coverExtension;
$pass->imageresize($cSource, $cDestination, $width=600, $height=600, $crop=false, $quality=72);
if ($s3->putObjectFile($cSource, "proaudiosocialstream", $coverImage, S3::ACL_PUBLIC_READ)) {$s3Cover ='http://bucket.s3.amazonaws.com/'.$coverImage;}else{return false;}
$data['user_cover_image_url'] = $coverImage;
}
if(empty($_FILES['user_avatar_url']['name'])) {
} else {
//Avatar Elements
$avatarName = $_FILES['user_avatar_url']['name'];
$avatarExtension=end(explode(".", $avatarName));
if($avatarExtension=='png') {$avatarExtension = 'jpg';}
$aName = $uid.'-'.$pass->generateRandomString($length=25);
$avatarImage = $aName.'.'.$avatarExtension;
$aSource = file_get_contents($_FILES['user_avatar_url']['tmp_name']);
$aDestination = '/var/www/html/tmp/avatar-'.uniqid().'.'.$avatarExtension;
$pass->imageresize($aSource, $aDestination, $width=400, $height=400, $crop=false, $quality=72);
if ($s3->putObjectFile($aDestination, "proaudiosocialstream", $avatarImage, S3::ACL_PUBLIC_READ)) {$s3Avatar ='http://bucket.s3.amazonaws.com/'.$avatarImage;}else{return false;}
$data['user_avatar_url'] = $avatarImage;
}

I think you did not configured php-fpm with nginx
nginx virtual host file should look like this for php-fpm
server {
listen 80;
server_name www.trakleaf.in trakleaf.in;
access_log access_file_path compression;
error_log error_file_path;
root root_directory;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/images/") {
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME root_directory$fastcgi_script_name;
}
}

Related

Laravel + nginX + Windows 10 + api routing issue (404 Error)

I am trying to make a very simple API request with above settings. It is working perfectly if I serve it with artisan serve command. But If I make the request with nginx, it gives 404 error. Thats why I guess the issue is with the nginX. my nginX conf is as follows.
server {
listen 80 ;
listen [::]:80 ;
root D:/sites/demo/public;
index index.php index.html index.htm ;
server_name laravel.local;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri /index.php = 404;
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}

Can´t reach laravel endpoints with Nginx (Windows)

I´m trying to reach laravel endpoints with Nginx in Laragon and in Windows. I have an Arduino Leonardo connected to wifi by a wifishield, and it reaches the service but always the index.php page or 404 not found. I´ve tried all nginx configurations but none helped.
This is the arduino code for connecting the server:
void httpRequest() {
client.stop();
Serial.println("\nStarting connection to server...");
if(client.connect(server, 8080)) {
client.println("GET /api_terrarium/api/get-actuators");
client.println("Connection: close");
client.println();
lastConnectionTime = millis();
} else{
Serial.println("connection failed");
}
}
The nginx config files are:
Server file:
server {
listen 8080;
server_name api_terrarium.test *.api_terrarium.test;
root "D:/laragon/www/api_terrarium/public/";
index index.html index.htm index.php;
#location / {
# try_files $uri $uri/ /index.php$is_args$args;
#autoindex on;
#}
location ~ \.php$ {
#try_files $uri /index.php =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php_upstream;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht {
deny all;
}
}
# This file is auto-generated.
# If you want Laragon to respect your changes, just remove the [auto.] prefix
# If you want to use SSL, enable it at: Menu > Nginx > SSL > Enabled
Default conf:
server {
listen 8080 default_server;
server_name localhost ;
root "/var/www/public";
index index.html index.htm index.php;
# Access Restrictions
allow 127.0.0.1;
allow all;
include "D:/laragon/etc/nginx/alias/*.conf";
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
location ~ \.php$ {
allow all;
include snippets/fastcgi-php.conf;
fastcgi_pass php_upstream;
#fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht {
}
}
And the laravel web.php:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::post('/add-new-parameter', [ 'uses'=>'ParametersController#addParameter']
);
Route::get('/get-parameter', ['uses'=>'ParametersController#getParameter']
);
Route::get('/get-historic', ['uses'=>'ParametersController#getHistoric']
);
Route::delete('/delete-historic', ['uses'=>'ParametersController#deleteHistoric']
);
Route::get('/get-actuators', ['uses'=>'ActuatorController#getActuators']
);
Nginx didn´t get the api.conf and perma choose the default one, so in Nginx.conf I commented
include "D:/laragon/etc/nginx/sites-enabled/*.conf";
and added
include "D:/laragon/etc/nginx/sites-enabled/api_terrarium.test.conf";

Nginx + CodeIgniter Posting To Controller 500 Error

I previously had this website on an Ubuntu/Apache host which has now been moved to a Debian/Nginx host. When I moved to Nginx it seems the form which used to work no longer works
How the form works is that it's hosted on a Wordpress website which is located at www.mycompany.com. It then posts the data to a controller which is hosted on the same server but using virtual hosts to site1.mycompany.com.
When I post the data, the form just hangs, looking at the console shows
POST https://site1.mycompany.com/request_form/submit 500 (Internal Server Error)
The CodeIgniter controller is called request_form and the submit function starts like this (to give you an idea)
public function submit()
{
$return = array('error' => false, 'msg' => '', 'error_data' => array());
$validation_rules = array();
//$this->form_validation->set_rules('serial_no', 'Outdoor Serial No', 'required');
$this->form_validation->set_rules('enquiry_type', 'Enquiry Type', 'required');
$this->form_validation->set_rules('txt_email', 'Email', 'required');
if(!empty($this->input->post('txt_email')))
{
$this->form_validation->set_rules('txt_email','email','valid_email|callback_email_exist');
}
$this->form_validation->set_rules('txt_phone', 'Phone', 'required');
$this->form_validation->set_rules('txt_address', 'Address', 'required|callback_check_address_for_state');
$this->form_validation->set_message('check_address_for_state','Address is not valid!');
My Nginx Config for site1.mycompany.com is
server {
server_name site1.mycompany.com;
root /var/www/html/site1.mycompany.com;
index index.php index.html index.htm;
autoindex on;
client_max_body_size 50M;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ /index.php;
}
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
There are no error logs in either /var/logs/nginx nor under CodeIgniter even when full logging is enabled. I have tried a variety of changes to the Nginx config with no avail.
Just try with these basic settings. (for easy debug just add echo "works"; die; in the home controller and check.)
In Ngnix
server {
server_name site1.mycompany.com;
root /var/www/html/site1.mycompany.com;
index index.html index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
In Config.php
$config['base_url'] = "http://site1.mycompany.com/";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

Laravel Route in NGINX on Windows machine didn't work well

I just install my nginx server on my windows laptop. Then I setup the nginx.conf file like this :
server {
listen 80;
server_name laravelninja.local;
root C:/blablabla/public;
index index.php;
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;
}
}
running the php-cgi using this syntax php-cgi.exe -b 127.0.0.1:9000
and the hosts also
127.0.0.1 laravelninja.local
It's running well at laravelninja.local/, but when I go to other route like laravelninja.local/pizzas, this error came out from nginx
2020/12/23 21:26:52 [error] 8980#11972: *7 CreateFile() "C:/blablabla/public/pizzas" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: laravelninja.local, request: "GET /pizzas HTTP/1.1", host: "laravelninja.local"
and the browser goes to google and search the laravelninja.local/pizzas
this is the code in my route :
Route::get('/', function () {
return view('welcome');
});
Route::get('/pizzas', function () {
return view('pizzas');
});
and the same level view of pizzas.blade.php as welcome.blade.php on the views folder.
is there any other option to solve this problem except using laragon ?
Add these 2 blocks in your config like this:
server {
#
# your configs...
#
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
}
Restart your NGINX server.
(I'm not sure about your other configs you have, but I believe the first block is what you want.)

nginx / varnish / magento - 500 Error when changing port

I have installed varnish on nginx. I have some really big problems.
my default.vcl is:
backend default {
.host = "127.0.0.1";
.port = "81";
}
my website virtual server is:
server {
listen 80;
root /var/www/site.com.ro/public_html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name www.site.com.ro;
access_log /var/www/site.com.ro/logs/log.access;
error_log /var/www/site.com.ro/logs/log.error error;
location / {
index index.php;
try_files $uri $uri/ #handler;
}
location #handler {
rewrite / /index.php;
}
location /blog {
alias /var/www/site.com.ro/public_html_blog/;
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php;
}
location ~ ^/blog(.+\.php)$ { ### This location block was the solution
alias /var/www/site.com.ro/public_html_blog/$1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 300;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
if (!-e $request_filename) {
rewrite / /index.php last;
}
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_read_timeout 300;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 80;
# Make site accessible from http://localhost/
server_name site.com.ro;
rewrite ^(.*) http://www.site.com.ro$1 permanent;
}
and the varnish file is:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
when I try to change the listen port for the website to 81 I get a 500 error...
can anyone help me? I don't know what I did wrong.
Varnish is configured to listen to port 80, and connect to localhost:81. nginx is configured to listen to port 80. You didn't mention the intended flow, but I'm taking a wild shot and guessing:
client -> varnish:80 -> nginx:81.
Do you spot the problem now?
Hint:
server {
listen 80;
Oh, and make sure you have a real similar setup in a test machine (virtualbox - or something) that you use when you dabble with settings you're not familiar with. That will give you time to understand why something is not working, and will gain you invaluable experience so you don't have to mess up the production site(s).

Resources