Images not found using Laravel with nginx and docker-compose - php

This is basically an extension on my question here. I have now added the permissions on storage folder and I do not get the 500 error anymore. But now I get 404 instead.
The image URL I'm trying is URL: http://localhost:8888/images/content/test/myimage.jpg
The server path to the image is /var/www/public/images/content/test/myimage.jpg
My nginx-config is the following:
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
worker_rlimit_nofile 100000;
events {
worker_connections 2048;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 8888;
root /var/www/public;
index index.php index.html index.htm;
client_max_body_size 100m;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass app:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
My guess is that it's something wrong with the config above but I have no idea what it might be. I have tried the solution suggested here but it did not do any difference at all.
Does anyone have any idea what to do?

It might be the path in this line: location ~ ^/.+\.php(/|$)
Try it like this:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;

Related

Time-out 504 Gateway Time-out nginx in wordpress-php-fpm

I want to setup WordPress PHP-fpm in Kubernetes, so I already setup that but there is some problem that currently I am facing with Nginx proxy, so when I am trying to install the woo-commerce plugin then it gives the error of
Installation failed: 504 Gateway Time-out 504 Gateway Time-out nginx padding to disable MSIE and Chrome friendly error page -> < ! - padding to disable MSIE and Chrome friendly error page ->
I don't know what's going wrong on proxy I already set the max value for proxy_read_timeout 100. but then also it will not work. I tried so many proxy time-out values but it didn't work, so here is my Nginx proxy config
wordpress.conf
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php;
#access_log /var/log/nginx/hakase-access.log;
#error_log /var/log/nginx/hakase-error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache phpcache;
fastcgi_cache_valid 200 301 302 60m;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
add_header X-FastCGI-Cache $upstream_cache_status;
fastcgi_cache_use_stale error timeout updating invalid_header http_500 http_503;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=phpcache:100m max_size=10g inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
The one working for me
location ~ \.php$ {
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 60;
fastcgi_read_timeout 60;
}
You must be running the two containers inside the single pod you can debug the logs of ingress and nginx of WordPress to check more details.
you can use this github as reference : https://github.com/harsh4870/Kubernetes-wordpress-php-fpm-nginx
Also, check the blog to understand more : https://medium.com/#harsh.manvar111/kubernetes-wordpress-php-fpm-nginx-73cb4f9aef02

Nginx php files loading slow

EDIT: I have noticed the first time you visit it to goes fast, and it also goes fast if you close the browser tab and re-visit it, but if you simply reload or visit it when you have a tab of it open it goes slow, it is really confusing.
today I come with a problem about PHP CGI, I am brand new to nginx and have just installed it, when I noticed I need to start PHP cgi also with it because with IIS it started it for me. so I start php with batch file below but the problem is... slow php files, they load really slowly even if its just html in them.
#ECHO off
echo Starting PHP, please wait!
C:\nginx\php7\php-cgi.exe -b 127.0.0.1:9054 -c C:\nginx\php7\php.ini
ping 127.0.0.1 -n 1>NUL
ping 127.0.0.1 >NUL
EXIT
Am I doing anything wrong with my batch file or nginx config below? (I have 2 configs) the example.com one is the website with a .php file and the nginx (localhost) just has index.html
localhost loads super fast but example.com one loads really slow because of php.
nginx.conf
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root C:\Users\Administrator\Dropbox\websites\local_website;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
include vhosts/*.conf;
}
example.com.conf
server {
listen ***.***.**.***:80;
server_name example.com www.example.com;
root C:\Users\Administrator\Dropbox\websites\php_website;
index index.php index.html;
log_not_found off;
charset utf-8;
#access_log logs/example.com-access.log main;
location ~ /\. {allow all;}
location / {
rewrite ^/(|/)$ /index.php?url=$1;
rewrite ^/([a-zA-Z0-9_-]+)(|/)$ /index.php?url=$1;
rewrite ^/(.*)\.htm$ /$1.php;
}
location = /favicon.ico {
}
location = /robots.txt {
}
location ~ \.php$ {
if (!-e $document_root$document_uri){return 404;}
fastcgi_pass localhost:9054;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I had the exactly same problem as you do. try changing your fastcgi_pass.
from this
fastcgi_pass localhost:9054
to this
fastcgi_pass 127.0.0.1:9054

Laravel routes getting not found on nginx/1.8

I use laravel 5.1 and nginx/1.8 it's the first time for me with Nginx Server
When i try to access laravel app home page the route working well
get('/', function () {
return view('welcome');
});
But when i try to access any other page
get('/home', function () {
return 'Home Page';
// Or Blade Page
//return view('home');
});
Nginx return
My settings file on /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
#root /usr/share/nginx/html;
root /var/www/nginx/html;
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Update
the last result of /var/log/nginx/error.log
#3 /var/www/nginx/html/laravel/vendor/laravel/framework/src/Illuminate
/Foundation/Exceptions/Handler.php(49):
Monolog\Logger->error(Object(Symfo
2016/01/11 22:59:38 [error] 22510#0: *31 directory index of "/var/www/nginx/html/laravel/" is forbidden, client: 127.0.0.1, server: _, request: "GET /laravel/ HTTP/1.1", host: "localhost"
Note:html/laravel -> laravel is the app name
Any Suggestions ?
Root needs to point to the public folder of your laravel installation. If you've installed laravel into /var/www/nginx/html, then it should be:
root /var/www/nginx/html/public

Nginx shows 403 page on all php errors

I have Amazon ec2 server running nginx + php-fpm-5.6
It opens php pages correctly when there are no errors, but if any kind of error occurs (php error or exception) it always displays the same page (/test.php is the requested url):
Forbidden
You don't have permission to access /test.php on this server.
Additionally, a 403 Forbidden error was encountered while trying to
use an ErrorDocument to handle the request.
I tried changing php "display_errors" option.
When I enable it all scripts begin to show 403 page. In php error log I see a warning message that I should define default timezone. When I define it with
date_default_timezone_set(...); in my scripts 403 error goes and appears only when a script has some mistake or if I write throw new Exception(); for example.
How can I bring back normal error messages with details of an error and place in file where it has occured?
Upd. My nginx configuration:
server {
listen 80 default_server;
server_name localhost;
root /var/www/html;
index index.php index.html;
client_max_body_size 200m;
access_log /var/log/nginx/admin.xuno.com.au.access.log;
error_log /var/log/nginx/admin.xuno.com.au.error.log;
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;
proxy_read_timeout 120;
}
}
Main nginx.conf
user dev-user;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}

Nginx with PHP is functioning correctly but then it stops working

I'm on Windows 8.1 64 bits, PHP 5.6.12 VC11 x64 Thread Safe, nginx 1.9.3. I configured nginx with PHP the way I wanted too (I'm still learning) and I ran it. I opened index.php and it worked, the page displayed correctly. Then I closed the server, opened it again and it stopped working, it sent me the error page instead. This has happened before.
Here's my nginx.conf:
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include fastcgi.conf;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 2;
#gzip on;
server {
listen 80 default_server;
server_name localhost;
root html;
index index.php;
#charset koi8-r;
access_log logs/host.access.log main;
location / {
try_files $uri $uri/ /index.php;
}
#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 html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
location ~* \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME c:/nginx/html/$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;
#}
}
}
Here are the start bat script and js (I run the js):
JS:
var objShell = WScript.CreateObject("WScript.Shell");
var result = objShell.Run("cmd.exe /c start-nginx.bat", 0);
// Give some startup time
WScript.Sleep(3000);
// Navigate to homepage
objShell.Run("http://localhost");
BAT:
#ECHO OFF
c:\nginx\nginx.exe
c:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
ping 127.0.0.1 -n 1>NUL
echo Starting nginx
echo .
echo .
echo .
ping 127.0.0.1 >NUL
EXIT
Here are the stop bat and js (I run the JS too):
JS:
var objShell = WScript.CreateObject("WScript.Shell")
var result = objShell.Run("cmd.exe /c stop-nginx.bat", 0)
BAT:
#ECHO OFF
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe
EXIT

Categories