Okay, i setup a debian install with ispconfig3 ,php5-fpm and nginx, the main site, drupal is working fine, even perfect. But i also have a modded phpbb3 board, in a subdir, named 'forum'.
Now for some reason i get the following error from nginx when accesing the dir:
'ERROR 500 - Internal Server Error!'
This is the content of the nginx directiv field(for vhost):
# search for already compressed files
gzip_static on;
gzip on;
# some images have no mime type
default_type image/jpeg;
# 404 generated from php can be rather slow. Uncomment with care
error_page 404 /index.php;
# disallow access to version control directory, but return 404, not to disclose information
location /.git {
return 404;
}
# robots.txt is important for search engines
location /robots.txt {
access_log off;
}
# This is mostly based on Drupal's stock .htaccess
location ~* ^.+(\.(txt|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ {
return 404;
}
# serve imagecache files directly or redirect to drupal if they do not exist
location ~* imagecache {
access_log off;
expires 30d;
try_files $uri #drupal;
}
# Drupal 7 image stylef
location ~* image/generate {
access_log off;
expires 30d;
try_files $uri #drupal;
}
# serve static files directly
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|swf|flv)$ {
access_log off;
log_not_found off;
expires 30d;
}
location #rewrite {
# Some modules enforce no slash (/) at the end of the URL
# Else this rewrite block wouldn't be needed (GlobalRedirect)
rewrite ^/(.*)$ /index.php?q=$1;
break;
}
# This rewrites pages to be sent to PHP processing
location #drupal {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
location / {
try_files $uri #cache;
}
# This will try to see if we have a boost file in place. no harm done if this is not used
location #cache {
# queries, drupal cookies, or not GET methods, all require PHP processing.
if ($query_string ~ ".+") {
return 405;
}
if ($http_cookie ~ "DRUPAL_UID" ) {
return 405;
}
if ($request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
error_page 405 = #drupal;
# Drupal uses 1978 - I am 4 years older than Dries :)
add_header Expires "Tue, 22 Sep 1974 08:00:00 GMT";
add_header Cache-Control "must-revalidate, post-check=0, pre-check=0";
try_files /cache/normal/$host/${uri}_.html /cache/mobile/$host/${uri}_.html /cache/perm/$host/${uri}_.css /cache/perm/$host/${uri}_.js /cache/$host/0$uri.html /cache/$host/0${uri}/index.html #drupal;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include /etc/nginx/fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
location /forum {
root /var/www/ashladan.net/web;
index index.php index.html index.htm;
location ~ ^/forum/(.+\.php)$ {
try_files $uri =404;
root /var/www/ashladan.net/web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include /etc/nginx/fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
}
location ~* ^/forum/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /var/www/ashladan.net/web;
}
}
It may be standard PHP response for uncaught exception / fatal / syntax error with no output.
You can either turn on error logging in php.ini and check your log file, or just at the beginning of your index.php file in this directory add two lines:
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
So if it is PHP's fault you will get more details on this error.
Related
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
Im trying to move a drupal site I started on my localhost to a server at home. The database is both exported from my localhost and stored on the server.
The content of the nginx.conf file is as follows
events {
worker_connections 768;
# multi_accept on;
}
http{
server {
listen 443 ssl;
######## S S L CONFIGURATIONS ##################
ssl_certificate /etc/ssl/Nov2021/STAR_site.edu.co.crt;
ssl_certificate_key /etc/ssl/Nov2021/site.edu.co.key;
access_log /var/log/nginx/KNH_nginx.vhost.access.log;
error_log /var/log/nginx/KNH_nginx.vhost.error.log;
root /var/www/html/arctic_kittiwake;
index index.php index.html index.htm;
###################################################
server_name site.edu.co
location / {
#try_files $uri $uri/ /index.php?q=$uri&$args;
try_files $uri /index.php?q=$uri$args;
}
location /site/ {
if (!-e $request_filename){
rewrite ^/site/(.*)$ /site/index.php break;
}
}
location ~ \.php$ {
fastcgi_index index.php;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
}
}
The directory where this file is stored is the /etc/nginx and the drupal site is stored in the /var/www/html/arctic_kittiwake/ directory.
I also have php7.4-fpm and mariadb-10.3 installed.
You are missing connection with php-fpm.
Example:
# In Drupal 8, we must also match new paths where the '.php' appears in
# the middle, such as update.php/selection. The rule we use is strict,
# and only allows this pattern with the update.php front controller.
# This allows legacy path aliases in the form of
# blog/index.php/legacy-path to continue to route to Drupal nodes. If
# you do not have any paths like that, then you might prefer to use a
# laxer rule, such as:
# location ~ \.php(/|$) {
# The laxer rule will continue to work if Drupal uses this new URL
# pattern with front controllers other than update.php in a future
# release.
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
# Ensure the php file exists. Mitigates CVE-2019-11043
try_files $fastcgi_script_name =404;
# Security note: If you're running a version of PHP older than the
# latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
# See http://serverfault.com/q/627903/94922 for details.
include fastcgi_params;
# Block httpoxy attacks. See https://httpoxy.org/.
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
# PHP 5 socket location.
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# PHP 7 socket location.
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
Full example is here https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/
I am a web developer and I build websites. But I have the following problem:
Since I can work from home (like probably most of us devs can do), I want to use nginx with php to continue working on websites. At work, one of my colleagues gave me one nginx configuration file which can serve multiple sites. I will post the whole code block below.
The problem is that I am working on windows 10 and I do not know how to make this code work on my machine.
My php version is PHP 7.3.12 which is located under C:\php.
My nginx version is 1.16.1 which is located under C:\nginx-1.16.1.
I appreciate every help I can get!
server {
index index.php index.html index.htm;
set $basepath "/home/nik/Code/";
set $domain $host;
set $dynroot "/var/www";
# check multi name domain to multi application
if ($domain ~ "^(.*)\.(.[^.]*)\.(site|vpnsite)$") {
set $customer $1;
set $developer $2;
set $rootpath "${developer}/${customer}/";
set $servername "${customer}.${developer}.site";
set $dynroot "$basepath/$rootpath";
}
if ($domain ~ "^(.*)\.(.[^.]*)\.laravel$") {
set $customer $1;
set $developer $2;
set $rootpath "${developer}/${customer}/";
set $servername "${customer}.${developer}.laravel";
set $dynroot "$basepath/$rootpath/public";
}
client_max_body_size 134M;
server_name "dev"
access_log "/home/nik/Code/App/nginx-logs/${servername}.access.log";
error_log "/home/nik/Code/App/nginx-logs/combined.error.log";
root $dynroot;
# check file exist and send request sting to index.php
location / {
try_files $uri $uri/ /index.php?$args;
autoindex on;
}
# allow execute all php files
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
# configure phpmyadmin path
location /phpmyadmin {
root /usr/share/;
index index.php;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 4k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
# disallow access to apache configs
location ~ /\.ht {
deny all;
}
# disallow access to git configs path
location ~ /\.git {
deny all;
}
}
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
}
}
I have a pretty standard setup with a symfony2-like app with a front controller, running on nginx 1.10 and Centos7. It all works as expected, blocks where expected etc.
server {
listen 80;
root /opt/my/code/web;
index app.php;
charset utf-8;
location / {
try_files $uri $uri/ /app.php$is_args$args;
}
# pass the PHP scripts to php5-fpm
location ~ ^/app\.php(/|$) {
# problem here
location ~ ^/recording {
add_header Content-Type audio/x-wav;
}
fastcgi_split_path_info ^(.+?\.php)(/?.*)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index app.php;
include /etc/nginx/fastcgi_params;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Prevents URIs that include the front controller. This will 404:
internal;
}
# return 404 for all other php files not matching the front controller
location ~ \.php$ {
return 404;
}
}
I have a few issues but the main one is that I want special handling for a URI matching /recording but it still has to go through the front controller. (This is not debatable, it HAS to go through the front controller and modify a response header if the URI matches /recording)
Since try_files redirects to location ~ ^/app\.php(/|$) nginx's $uri parameter used for location matching gets updated to /app.php, so any nested locations won't work.
I cant use add_header outside of the front controller block because any add_header directives get dropped on an internal redirect.
Obviously I can't use location if with add_header either.
This is easy in apache, but the only remote solution I have found uses a third party lua module and the installation docs are a bit thin on that and the thought of compiling that in from source on centos is giving me heart palpitations.
If internal redirect bother us, lets remove internal redirect :) You can solve it easy with fastcgi config duplication
server {
listen 80;
root /opt/my/code/web;
index app.php;
charset utf-8;
location / {
try_files $uri $uri/ /app.php$is_args$args;
}
location ~ ^/recording {
add_header Content-Type audio/x-wav;
fastcgi_pass unix:/var/run/php-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_NAME /app.php;
fastcgi_param SCRIPT_FILENAME $document_root/app.php;
}
# pass the PHP scripts to php5-fpm
location ~ ^/app\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/?.*)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index app.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Prevents URIs that include the front controller. This will 404:
internal;
}
# return 404 for all other php files not matching the front controller
location ~ \.php$ {
return 404;
}
}
Second solution works only if you know content type of all other requests. We can use variables. (btw, I don't suggest this solution because harder to support and not cute :))
server {
listen 80;
root /opt/my/code/web;
index app.php;
charset utf-8;
location / {
try_files $uri $uri/ /app.php$is_args$args;
set $ct "text/html";
}
location ~ ^/recording {
try_files $uri $uri/ /app.php$is_args$args;
set $ct "audio/x-wav";
}
# pass the PHP scripts to php5-fpm
location ~ ^/app\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/?.*)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index app.php;
include /etc/nginx/fastcgi_params;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
add_header "Content-Type $ct;
# Prevents URIs that include the front controller. This will 404:
internal;
}
# return 404 for all other php files not matching the front controller
location ~ \.php$ {
return 404;
}
}