After Letsencrypt, I can no longer write images to my server. Help me please


#1

Hello guys. All right with you? :slight_smile:

I have a problem and maybe you can give me a light. :sparkler:

Since I used the “ee site update mydomain.com --letsencrypt” option, I can no longer write images coming from my WEBSERVICE (SOAP) on my server. I have a PHP code which is responsible for writing to the server, but when using the above command, it can not write to the server anymore. I do not understand much of Nginx and etc, so I came to ask for your help. I’ve already broken my head here for a week and I can not figure out where to start. Here’s the code I’m using to make the link between WEBSERVICE and my site:

<?php
// ImgUpload.php

require_once("settings.php");

$erro = false;
$erro_cont = 0;
$erro_mensagem = '';

$loja = false;
if(isset($_GET['loja']) && !empty($_GET['loja'])) if($_GET['loja'] == 1) $loja = true;

if(file_put_contents($logdir."upload.log", date("Y-m-d H:i:s") . "\n" . print_r($_FILES, true) . "\n" , FILE_APPEND | FILE_TEXT) < 1) {
	$erro = true;
	$erro_cont++;
	$erro_mensagem .= $erro_cont . ') Log nao foi gravado' . "\n";
}

// Se trata de acesso para Upload?
if (count($_FILES) < 1 || !isset($_FILES['imagem'])) {
	$erro = true;
	$erro_cont++;
	$erro_mensagem .= $erro_cont . ') Nao foi enviado arquivo em POST ou variavel POST nao recebe nome "imagem"' . "\n";
}

if(!$erro) {
	
	$micro_date = microtime();
	$date_array = explode(" ",$micro_date);

	if($loja) $uploaddir_ = 'store/';
	else $uploaddir_ = 'film/' . date('Y/m/',$date_array[1]);
	$uploaddir = $uploaddir_base . $uploaddir_;

	// Cria diretório se não existe
	if (!file_exists($uploaddir)) {
		if(!mkdir($uploaddir, 0755, true)) {
			$erro = true;
			$erro_cont++;
			$erro_mensagem .= $erro_cont . ') Nao foi possivel criar o diretorio ' . $uploaddir . "\n";
		}
	}

	// Verifica o tipo de arquivo
	$extensao = '';
	switch ($_FILES['imagem']['type']) {
		case 'image/png':
			$extensao = 'png';
			break;
		case 'image/jpeg':
			$extensao = 'jpg';
			break;
		case 'image/gif':
			$extensao = 'gif';
			break;
		case 'application/octet-stream':
			$name_ext = end(explode(".",$_FILES['imagem']['name']));
			if($name_ext == 'gif' || $name_ext == 'png' || $name_ext == 'jpeg' || $name_ext == 'jpe' || $name_ext == 'jpg')
				$extensao = $name_ext;
			else {
				$erro = true;
				$erro_cont++;
				$erro_mensagem .= $erro_cont . ') Erro de tipo de arquivo (somente: png, jpg, jpeg, jpe e gif)' . "\n";
			}
			break;
		default:
			$erro = true;
			$erro_cont++;
			$erro_mensagem .= $erro_cont . ') Erro de tipo de arquivo (somente: png, jpg e gif)' . "\n";
			break;
	}

	if(!$erro) {

		$date = date("Ymd-His",$date_array[1]);
		$uploadfile_name = $date . "-" . round($date_array[0]*1000000) .'.' . $extensao;
		$uploadfile = $uploaddir . $uploadfile_name;

		if (!move_uploaded_file($_FILES['imagem']['tmp_name'], $uploadfile)) {
			$erro = true;
			$erro_cont++;
			$erro_mensagem .= $erro_cont . ') Nao foi possivel fazer o upload do arquivo. Veja mais:' . "\n" . print_r($_FILES['imagem'], true) . "\n";
		}
		
	}

}

if($erro) {
	echo $erro_mensagem;
}
else {
	header('Content-Type: application/xml; charset=utf-8');
	echo '<?xml version="1.0"?>'."\n<root>\n<imagem>https://mydomain.com/wp-content/uploads/" . $uploaddir_ . $uploadfile_name . "</imagem>\n</root>";
}

?>

I believe it is something simple to solve, but I lack the knowledge necessary for this task. Thanks in advance for any suggestion.


#2

No Suggestions? :sweat:


#3

Any clue where I can start investigating? I really do not understand much of development. I usually work with design. Thanks for any directions.


#4

Is there anything useful in the error log? /var/log/nginx/yoursite.com.error.log


#5

Thanks @fghafoor e @marty!

Just delete the force-ssl-domain.com.conf file from /etc/nginx/conf.d

And then goto /etc/nginx/sites-available and open the config filed named just domain.com from the directory and add listen 80; after server {

Restarted server, cleaned cached and it all worked fine after that. Http and Https both with http as default.