I have PHP 7.2.17 and Nginx 1.15.9 on Ubuntu 19.04.
I have this nginx configuration :
server {
listen 80;
listen [::]:80;
server_name dev.frameworkcms.com;
set $rootpath "/var/www/html/perso/framework-cms test";
error_log "/var/www/html/perso/framework-cms test/logs/error.log" error;
# combined by default
access_log "/var/www/html/perso/framework-cms test/logs/access.log";
root $rootpath/web;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index Resources.php;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php7.2-fpm.sock;
}
}
I tried with the port 9000 as well.
i can see the index.html at the project root but not the file web/Resources.php.
I always have a 502 Bad Gateway. Logs are empty.
Edit
I just added a line try_files \$uri /Resources.php; at the beginning of the location block. Now the php file is offered for download...
Edit
Thanks to #Pete Cooper, I have found that the .sock file is not the good one.
Here is the new version of the file :
server {
listen 80;
listen [::]:80;
server_name dev.frameworkcms.com;
set $rootpath "/var/www/html/perso/framework-cms test";
error_log "/var/www/html/perso/framework-cms test/logs/error.log" error;
# combined by default
access_log "/var/www/html/perso/framework-cms test/logs/access.log";
root $rootpath/web;
location ~ \.php$ {
try_files \$uri /Resources.php;
fastcgi_intercept_errors on;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index Resources.php;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}
I now have a 500 Internal Server Error.
I precise that I work locally.
Try restarting your php-fpm service.
Related
Trying to setup 2 applications with same domain, but different paths. I am running php-fpm with nginx and would need every uri starting with "/sub" to be directed to index.php file of /var/www/sub and all others to be directed to /var/www/main.
Latest test can be found below which resolves my locations (as I see in logs), but in error log I get:
open() "/var/www/sub/test/test" failed (2: No such file or directory)
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/default_access.log;
error_log /var/log/nginx/default_error.log debug;
location / {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
alias /var/main/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
location ^~ /sub {
access_log /var/log/nginx/sub_access.log;
error_log /var/log/nginx/sub_error.log debug;
alias /var/sub/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
What might be wrong with this configuration or where should I look next?
EDIT: changed alias paths from /var/main to /var/main/public and /var/sub to /var/sub/public
I have installed a orocrm on a AWS Lightsail VPS with Nginx & PHP7. orocrm installed without a hitch but I'm using Nginx for the first time and my virtual host doesn't seem to be working.
sites-available/default:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index app.php index.php index.html;
server_name 34.127.224.10;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I then purchased & pointed crmdomain.com to my instance and created another file.
sites-available/crm:
server {
listen 80;
server_name crmdomain.com www.crmdomain.com;
root /var/www/html/crm/web;
index app.php;
error_log /var/log/nginx/orocrm_error.log;
access_log /var/log/nginx/orocrm_access.log;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location #rewrite { rewrite ^/(.*)$ /app.php/$1; }
location / {
try_files $uri /app.php$is_args$args;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_index app.php;
fastcgi_read_timeout 10m;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I honestly don't know most of what is above, it's mostly based on tutorial and apache experience.
Errors
Domain based
- crmdomain.com -> 403 Forbidden nginx/1.10.0 (Ubuntu)
- crmdomain.com/app.php -> No input file specified.
- crmdomain.com/app_dev.php -> No input file specified.
- crmdomain.com/index.nginx-debian.html -> Welcome to nginx!
- crmdomain.com/user/login -> 404 Not Found nginx/1.10.0 (Ubuntu) **This is what should word**
Static IP based
- 34.127.224.10 -> 403 Forbidden nginx/1.10.0 (Ubuntu)
- 34.127.224.10/crm/web/ - No input file specified.
- 34.127.224.10/crm/web/app.php - No input file specified.
- 34.127.224.10/crm/web/app_dev.php - No input file specified.
- 34.127.224.10/index.nginx-debian.html -> Welcome to nginx!
- 34.127.224.10/crm/web/app.php/user/login -> 404 Not Found nginx/1.10.0 (Ubuntu) **This is what should word**
What am I doing wrong?
It's weird how often I answer my own questions:
I was able to change the default files and remove the extra virtual host. Since the server was only going to host the one app.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 34.127.224.10 crmdomain.com www.crmdomain.com;
root /var/www/html/crm/web;
index app.php app_dev.php index.php;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config|install)\.php(/|$) {
#fastcgi_pass 127.0.0.1:9000;
# or
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
error_log /var/log/nginx/orocrm_error.log;
access_log /var/log/nginx/orocrm_access.log;
}
I was working with this config from 2 years without any problem
sudenly I face not found error message from niginx
and its come only when the link has "?"
sample
domain/index.php?a=browse&b=category&id=1
if open the normal link, its working (without "php?")
domain/index.php
domain/[any other php file].php
site config (changed user info)
server {
listen *:80;
server_name domain;
rewrite_log on;
root /home/user/public_html/;
location / {
index index.php index.html index.htm ;
}
location ~*^.+\.jpg|jpeg|gif|css|html|png|js|ico|bmp|zip|rar|txt|pdf|doc)$ {
root /home/user/public_html/;
# expires max;
access_log off;
}
location ~ ^/.+\.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}
}
try to use ip change it from
server_name domain;
to
server_name serverip;
and test url
serverip/index.php?a=browse&b=category&id=1
you can check it else with ssh comand
wget localhost/index.php?a=browse&b=category&id=1
if work , check any firewall or any services like cloudflare
I would like to serve rails, php and static html from the same nginx like this:
example.com - hits php
example.com/app - hits rails
example.com/static - hits static
This situation may be temporary (may be split to multiple servers at some point), so I would like to avoid changes to the code (adding scope or namespace to rails routes - I would like rails to treat "example.com/app" as root).
What should my nginx.conf look like?
I used this page from the passenger docs as reference and tried something like this:
server {
server_name example.com;
listen 80;
root /var/www/php;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
location ~ ^/app(/.*|$) {
alias /var/www/rails/current/public$1;
access_log /var/www/rails/current/log/access.log;
error_log /var/www/rails/current/log/error.log;
passenger_base_uri /app;
passenger_app_root /var/www/rails;
passenger_document_root /var/www/rails/currnet/public;
passenger_enabled on;
passenger_app_env production;
passenger_friendly_error_pages on;
passenger_ruby /usr/local/rvm/gems/ruby-2.1.5#app/wrappers/ruby;
client_max_body_size 4G;
keepalive_timeout 10;
}
}
but I get "not found"
I nearly got it right.
I had the wrong passenger_base_uri.
This is what finally worked for me:
server {
server_name example.com;
listen 80;
root var/www/php;
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
location ~^/app(/.*|$) {
alias /var/www/rails/current/public$1;
access_log /var/www/rails/current/log/access.log;
error_log /var/www/rails/current/log/error.log;
passenger_base_uri /app;
passenger_app_root /var/www/rails/current;
passenger_enabled on;
passenger_app_env production;
passenger_friendly_error_pages on;
passenger_ruby /usr/local/rvm/gems/ruby-2.1.5#app/wrappers/ruby;
}
client_max_body_size 4G;
keepalive_timeout 10;
}
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;
}