Error: no input file specified. Laravel with docker nginx-proxy - php

probably somebody faced this issue.
Through the time I get error "no input file specified" from nginx.
There is the log from nginx container "FastCGI sent in stderr: "Unable to open primary script: /var/www/public/index.php (No such file or directory)" while reading response header from upstream".
It happens only for https, on local machine allright.
There is a full log
As you can see, sometimes I got response 200, sometimes 404, from same file.
This is my nginx config:
server {
index index.php index.html index.htm;
root /var/www/public;
location ~ /.well-known/acme-challenge {
allow all;
root /var/www;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
rewrite ^/core/authorize.php/core/authorize.php(.*)$ /core/authorize.php$1;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}

I have been solved the problem. Instead nginx I set up apache, because laravel 5.8 refuses to work with nginx. Latest version of laravel works properly with nginx in docker

Related

Omeka-s and Nginx - loop install

I have a machine with latest PHP and MySQL. I need to use Nginx. I managed to serve Omeka using this recipe:
https://www.nginx.com/resources/wiki/start/topics/recipes/omeka/
When I go to my address I am presented with the ‘Install Omeka S - Create the first user’ page. When I fill it in and I submit, the response is the same page with an empty form, i.e. I’m stuck in a loop. The POST response in the browser console gives me a 404-not found error.
I feel I’m very close, can anyone shed some light on this? I feel that Omeka should not support Apache exclusively. Is this a Omeka-s issue? Am I overlooking something obvious?
Thanks.
OK, I found out what the issue is. The Nginx recipe I linked in my question is valid for Omeka, not Omeka-s. For Omeka-s one has to remove the /install and also edit the /admin location. This is the working configuration:
server {
server_name omeka.domain.tld;
root /var/www/omeka;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
try_files $uri /index.php?$args;
}
location /admin {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass unix:/tmp/phpfpm.sock;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Update
I've pushed this recipe to Nginx wiki:
https://www.nginx.com/resources/wiki/start/topics/recipes/omeka-s/

Nginx + php-fpm + zend3 - No input file specified

I'm using vagrant homestead machine as local development environment and I'm having trouble configuring a new zend 3 project.
Actually I have other projects on the same machine and they're working ok.
This one is giving me a "No input file specified" no matter what I put in the configuration file.
I'm running nginx 1.15.8, php7.3 in vagrant homestead 7.
I tried many solutions provided in this site but none was useful.
This is my vhost file:
server {
listen 80;
listen 443 ssl http2;
server_name simulador-preferencias.test;
root /home/vagrant/code/simulador-preferencias/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/simulador-preferencias.test.log;
error_log /var/log/nginx/simulador-preferencias.test-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
location ~ /\.ht {
deny all;
}
}
}
Can anyone help me get this configuration right?
Thanks in advance.
I finally solved the problem.
After you add the vhost to the vagrant machine and edit the Homestead.yml file to add the new site you have to run the following command to generate de correct configuration:
vagrant up --provision
Note that you'll have to stop the machine to be able to edit the Homestead.yml file or else you'll get an error message.
Stop the machine with:
vagrant halt

Serving Laravel from a directory

I am currently using a javascript framework being served up using Nginx, for example on the following url
www.myjsapp.com
I am also using Laravel 5.6 to build an API.
Instead of building 2 hosts, one for the JS app and one for Laravel, I want to be able to serve up the Laravel API on the following URL.
www.jsapp.com/api
Is this possible or do I have to always use 2 hosts?
The nginx server block for myjsappcom is as follows;
server {
listen 80;
listen 443 ssl http2;
server_name .myjsapp.com;
root "/home/project/myjsapp";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/myjsapp.com-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/myjsapp.com.crt;
ssl_certificate_key /etc/nginx/ssl/myjsapp.com.key;
}
You can separate the servers using location blocks in your nginx config file:
different /location blocks will capture different url schemes and pass them to the respective servers (node or laravel).
server {
server_name mysjapp.com;
#other configurations like root, logs
location / {
#node server config
}
location /api {
#laravel server config
}
}

Does nginx fastcgi_pass support variables?

I would like to use dynamic host resolution with nginx and fastcgi_pass.
When fastcgi_pass $wphost:9000; is set in the conf then nginx displays the error
[error] 7#7: *1 wordpress.docker could not be resolved (3: Host not found),
but when I set fastcgi_pass wordpress.docker:9000;it is working except for the fact the that after a wordpress restart nginx still points to an old ip.
server {
listen [::]:80;
include /etc/nginx/ssl/ssl.conf;
server_name app.domain.*;
root /var/www/html;
index index.php index.html index.htm;
resolver 172.17.42.1 valid=60s;
resolver_timeout 3s;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args; ## First attempt to serve request as file, then as directory, then fall back to index.html
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
set $wphost wordpress.docker;
# pass the PHP scripts to FastCGI server listening on wordpress.docker
location ~ \.php$ {
client_max_body_size 25M;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass $wphost:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
log_not_found off;
expires 168h;
}
# deny access to . files, for security
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
}
I have different virtual host configuration where I use proxy_pass http://$hostname; and in this setup everything is working as expected and the host is found.
After trying different options I wonder if fastcgi_pass does support variables
It does work if you pass the upstream as a variable instead, for example:
upstream fastcgi_backend1 {
server php_node1:9000;
}
upstream fastcgi_backend2 {
server php_node2:9000;
}
server {
listen 80;
server_name _;
set $FASTCGI_BACKEND1 fastcgi_backend1;
set $FASTCGI_BACKEND2 fastcgi_backend2;
location ~ ^/site1/index.php$ {
fastcgi_pass $FASTCGI_BACKEND1;
}
location ~ ^/site2/index.php$ {
fastcgi_pass $FASTCGI_BACKEND2;
}
}

How to correctly configure Nginx for PHP (Yii framework and Zurmo)

I am trying to setup Zurmo CRM on my local machine (Win8x64). After installing all the requirements I want to get started with the actual installation. The problem is that it seems the paths are not correctly passed from NGinx to FastCGI PHP. Here is my Nginx serve configuration:
server {
listen 80;
server_name zurmo.local;
root html/zurmo.local;
set $index "index.php";
charset utf-8;
location / {
index index.html $index;
try_files $uri $uri/ /$index?$args;
}
location ~ ^/(protected|framework|themes/\w+/views) {
deny all;
}
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(.*)$;
set $fsn /$index;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
}
location ~ /\.ht {
deny all;
}
}
As a result, when I make a call to zurmo.local (which is added to hosts file) i get "This webpage has a redirect loop" with a URI that looks like this http://zurmo.local/app/app/ [...] /app/app/index.php If instead of $document_root$fsn and I comment the PATH_INFO and PATH_TRANSLATED than I get No input file specified. with a URI that looks like http://zurmo.local/app/app/index.php
Looking further into it, when I have added access_log html/zurmo.local/logs/access.log; the Nginx error.log shows me the following: [timestamp] [emerg] 4064#3660: CreateFile() "[path to stack]\nginx/html/zurmo.local/logs/access.log" failed (3: The system cannot find the path specified). As you can see the directory separator is not consistent.
One last note, my Nginx home directory is situated at nginx/html which is in fact a smlink to of ../home This is purely for keeping my file structure in a way that fits my day to day work.
How can I correctly configure Nginx in order to proceed (with the Zurmo installation) ?
I know this is an old question, but here is what I have done to make nginx + zurmo work.
server {
listen 80;
server_name zurmo.local;
root /home/www/zurmo.local;
access_log /var/log/nginx/zurmo.access.log main;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ ^/(protected|framework|themes/\w+/views) { deny all; }
location ~ /\. { deny all; access_log off; log_not_found off; }
location = /favicon.ico { log_not_found off; access_log off; }
location ~ \.(js|css|png|jpg|gif|ico|pdf|zip|rar)$ {
try_files $uri =404;
}
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_read_timeout 600s;
fastcgi_send_timeout 600s;
}
}
I don't think you need the if() statement in your *.php block. In my nginx setups that's all i ever needed:
# Process PHP files
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Include the standard fastcgi_params file included with nginx
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

Categories