I have nginx and hhvm installed and running as processes on a ubuntu VM. The configs are copied below. I have an index.php file in /usr/share/nginx/html (pointed to by nginx) but when I try to access the site beign served by nginx, I get the following error about hhvm:
/var/log/nginx/error.log
2016/10/04 12:03:05 [crit] 12443#0: *1 connect() to unix:/var/run/hhvm/hhvm.sock failed (2: No such file or directory) while connecting to upstr
eam, client: xx.xxx.xxx.xxx, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/hhvm/hhvm.sock:", host: "xx.xx.xx.xx"
Nginx config (part of config)
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
index index.php;
try_files $uri $uri/ $uri/index.php$args /index.php$args;
}
location /mysql {
index index.php;
}
location ~* \.(php)$ {
try_files $uri = 404;
location ~ \..*/.*\.php$ {return 404;}
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I have checked - bothh nginx and hhvm processes are running. Any thoughts on how to troubleshoot this further?
Update:
I changed the server.ini file in /etc/hhvm to the following and restarted the service but it does not appear to have done the job
hhvm.server.file.socket=/var/run/hhvm/hhvm.sock
I commented out the 9000 port being used previously.
Update:
After making the server.init change and restarting hhvm, I get the following error in /var/log/hhvm/error.log:
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to read pid file /var/run/hhvm/pid for any meaningful pid
Unable to start page server
Shutting down due to failure(s) to bind in HttpServer::runAndExitProcess
The /var/run/hhvm directory is owned by www-data
I ended up running hhvm on port 9000 and pointed nginx (fasgcgi_pas) to point to the port (instead of using the file socket option).
Related
I was running Ubuntu server 20.04 quite successfully with Ired mail and 2 websites, one of them with WordPress.
I wanted to install Nextcloud, to do that I had to reinstall php-fpm to generate php7.4-fpm.sock. After this Nextcloud worked, but my other websites stopped working with error '502 Bad Gateway'.
So to say the least, I'm very confused!
I followed this article to install Nextcloud and set up the sites-enabled .conf file as per instructions: https://www.linuxbabe.com/ubuntu/install-nextcloud-ubuntu-20-04-nginx-lemp-stack/amp
I think I understand that the .conf file used to listen on 127.0.0.1:XXXX and now listens on php7.4-fpm.sock?
Here is the .conf file that I have put together for my website after re-installing php-fpm:
#
# Note: This file must be loaded before other virtual host config files,
#
# HTTPS
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name SOMEWEBSITE www.SOMEWEBSITE;
error_log /var/log/nginx/localhost.error_log info;
root /var/www/SOMEWEBSITE/html;
index index.php index.html;
include /etc/nginx/templates/misc.tmpl;
include /etc/nginx/templates/ssl.tmpl;
include /etc/nginx/templates/iredadmin.tmpl;
include /etc/nginx/templates/roundcube.tmpl;
include /etc/nginx/templates/sogo.tmpl;
include /etc/nginx/templates/netdata.tmpl;
include /etc/nginx/templates/php-catchall.tmpl;
include /etc/nginx/templates/stub_status.tmpl;
location / {
try_files $uri $uri/ /index.php?q=$uri$args;
}
# PHP handling
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
ssl_certificate /etc/letsencrypt/live/SOMEWEBSITE/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/SOMEWEBSITE/privkey.pem; # managed by Certbot
}
# Redirect http to https
server {
listen 80;
listen [::]:80;
server_name SOMEWEBSITE www.SOMEWEBSITE;
return 301 https://$host$request_uri;
}
I have checked the file permissions for php7.4-fpm.sock
ll /var/run/php/ | grep php
-rw-r--r-- 1 root root 3 May 22 21:13 php7.4-fpm.pid
srw-rw---- 1 www-data www-data 0 May 22 21:13 php7.4-fpm.sock=
lrwxrwxrwx 1 root root 30 May 22 21:13 php-fpm.sock -> /etc/alternatives/php-fpm.sock=
and I think it looks ok.
here is the log file:
2021/05/23 20:32:52 [error] 43596#43596: *305 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xxx.xxx, server: SOMEWEBSITE, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9999", host: "SOMEWEBSITE"
2021/05/23 20:32:53 [info] 43596#43596: *305 client xx.xx.xxx.xxx closed keepalive connection
Any Ideas? Need any more information? Thank you in advance for looking.
PHP-FPM can listen using two method for accepting fastcgi request. using TCP Socket or with Unix Socket.
You can sepecify it in php-fpm configuration, In Ubuntu the configuration is in /etc/php/7.4/fpm/pool.d/www.conf and check listen configuration.
If you want to use unix socket, use configuration below.
listen = /run/php/php7.4-fpm.sock
For TCP Socket.
listen = 127.0.0.1:9000
Next in nginx you can specify fastcgi_pass based on fpm configuration. If you using Unix socket, all your website, include Nextcloud must be using Unix Socket.
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
If you using TCP Socket, you must change the nginx configuration for Nextcloud to pass from TCP Socket.
fastcgi_pass 127.0.0.1:9000;
I have faced this issue as well. the problem is php-fpm didnt listen port 9999 (In my case i use port 9999). To make /mail/ work. u need to change below config file. change ip:port change to socket
/etc/php/fpm/pool.d/www.conf
listen = /var/run/php/php7.2-fpm.sock
/etc/nginx/templates/fastcgi_php.tmpl
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
I am trying to install nginx and php-fpm docker images in AWS Fargate without any success running out of options, what I see is either the nginx container unable to route the traffic to php container or php container unable to read files from EFS file system.
I have EFS file system holding sample index.html and index.php files in root folder and this EFS is shared with two containers nginx and php-fpm mounted from volumes in AWS Task definition creation wizard.
when I navigate to the ELB friendly DNS name I can successfully load index.html page but not index.php page I get "Primary script unknown" while reading response header from upstream, client: x.x.x.x, server: *.amazonaws.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000".
Changed upstream value to php:9000; or 127.0.0.1:9000; or resolver 127.0.0.11 none of them worked.
I got same error locally but if I hardcore fastcgi upstream and server_name fields with actual IP address in default.conf and listen=ipaddress of phpcontainer:9000 in www.conf file in pgp-fpm container this resolved the issue locally but in AWS fargate the IP's all ways change after restarting container any advise appreciated.
server {
listen 80;
#root /usr/share/nginx/html;
#local testing for docker-compose up
root /php;
index index.php index.html index.htm;
#server_name *.amazonaws.com;
server_name x.x.x.x; #local testing
#set $upstream 127.0.0.1:9000;
set $upstream x.x.x.x:9000; #local testing
location / {
try_files $uri $uri/ =404;
}
location /dataroot/ {
internal;
alias /usr/share/nginx/html/moodledata/;
}
location ~ ^(.+\.php)(.*)$ {
#root /usr/share/nginx/html;
#local testing
root /php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_index index.php;
fastcgi_pass $upstream;
include /etc/nginx/mime.types;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Finally figured out the issue after trying multiple combinations, its causing from root path which is different to each container nginx (/usr/shr/nginx/html) and php (/var/www/html)....the error message doesnt help for newbies working in php and linux world.
After changing the nginx root path as /var/www/html same as php-fpm container /var/www/html the issue was resolved of course the permissions has to be taken care of if your accessing the EFS volume mounts.
I am learning Laravel using its tutorial. I installed Laravel and the required stacks using LaraDock.
Nginx returns File not found when I go to the IP where the app is running. Below is my NGINX configuration.
server {
root /var/www/laravel/public/;
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
This is the error from NGINX error log.
2016/08/19 08:53:06 [error] 47#47: *16 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 192.168.99.1, server: , request: "GET / HTTP/1.1", upstream:
"fastcgi://111.13.0.5:9000", host: "192.168.99.100"
To be sure you have index.php in /var/www/laravel/public/
run command
docker-compose exec nginx ls /var/www/laravel/public/
If you don't have index.php in the folder, probably your project folder mounted wrong.
Did you edit .env, or docker-compose.yml file?
Where you put laradock folder relative to your project folder
I'm getting a 502 Bad Gateway error with PHP7 and nginx 1.9.9 installed on Ubuntu 14.04 when I try to access any .php files. .html files load as expected.
I've updated the default.conf to:
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.html index.htm index.php;
server_name localhost;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I've updated php.ini with cgi.fix_pathinfo = 0 and then rebooted the server, and am still getting the 502 error with all .php files. I have checked to ensure php7.0-fpm.sock is installed and in the proper location.
This is the error I'm getting from the nginx log 2016/01/19 19:14:54 [error] 1466#1466: *1 open() "/usr/share/nginx/html/xmlrpc.php" failed (2: No such file or directory), client: 85.159.237.13, server: localhost, request: "POST /xmlrpc.php HTTP/1.0", host: "my.ip.address"
I've searched for the answer for quite a while and I'm out of ideas. Does anyone have any suggestions?
This is mostly because your nginx and php7.0-fpm were not run under the same user. Edit nginx.conf and change "user nginx" to "user www-data"
By the way, "client: 85.159.237.13", that was a script boy, I think.
I have nginx working with arch linux. I am having trouble adding php and fastcgi. I installed the php and php-fpm packages. php-fpm service is on. When I access a file with a php extension, the browser displays the nginx error page and I get the following nginx error log message added:
2013/01/02 22:39:43 [error] 721#0: *27 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.13, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "192.168.1.19"
the contents of the php file seem to make no difference. I have been unable to locate php error log or create my own. I added the following to /etc/php/php.ini:
error_log = /var/log/php_error.log
and I made the file world writable but nothing goes there. I added the following to /etc/nginx/nginx.conf:
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi.conf;
}
uncommenting the commented lines changes nothing. Commenting the uncommented lines changes the browser page displayed from error page to file not found page.
Any help would be greatly appreciated. Thanks in advance.
Try changing your configuration file to this:
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
I figured it out. I had to uncomment a line in the php-fpm.conf file to have fastcgi listen on the right port.