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.
Related
I am completely new to nginx .
I have project based on angular js which have a index.html, and on a certain event i perform a angular http request to x.php file and fetches the response from it.
Its running perfect on my local system and a apache based private hosting server.
I created a free tier ec2 instance and started a centos based linux instance on which i hosted the code and installed nginx .
Here is my nginx config
server {
listen 80;
server_name mydomain.co.in www.mydomain.co.in;
location / {
root /var/www/html/indm;
index index.php index.html index.htm;
try_files $uri/ $uri /index.php?$query_string =404;
}
location ~ \.php$ {
try_files $uri $uri/ /index.php?q=$uri&$args =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
add_header Access-Control-Allow-Origin *;
proxy_set_header Access-Control-Allow-Origin $http_origin;
}
error_page 500 502 503 504 /50x.html;
At first it was giving me 500 gateway error when the http request was performed on that php file. I check in the XHR request.Here is the error in nginx error.log
[error] 17193#0: *2 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 42.111.38.254
I searched a bit and changed appended a "=404" to try uri statement. But now it redirect to a 404 . I want to run that php file.
the server
Nginx server is running
php fpm is also running
Please help
The location ~ \.php$ block has no root. Move the root statement into the server block so that the same value is inherited by both location blocks.
For example:
server {
...
root /var/www/html/indm;
location / {
...
}
location ~ \.php$ {
...
}
...
}
So, I was trying to setup mysite.com/blog initially, but got pretty fed up with it, so i setup blog.mysite.com instead.
It successfully loads the index file: index.htm, but if i try to access a file info.php it fails saying: 502 bad gateway, i checked /var/log/nginx/error.log and it says:
2016/12/17 09:24:13 [error] 1042#0: *4 connect() failed (111:
Connection refused) while connecting to upstream, client: x.xx.xx.xx,
server: blog.mysite.com, request: "GET /info.php HTTP/1.1", upstream:
"fastcgi://127.0.0.1:9000", host: "blog.mysite.com"
I installed php via: sudo apt-get install php5-fpm php5-mysql from this tutorial: link
My nginx config in /etc/nginx/sites-enabled/myblog is:
server {
listen 80;
root /home/www/flask-deploy/myblog;
fastcgi_index index.php;
index index.html index.htm index.nginx-debian.html;
server_name blog.mysite.com www.blog.mysite.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
What am I doing wrong?
Thank you so much!
First of all, your nginx config has bad path to php-fpm.sock. (You error.log is right ;) )
1) Which PHP version are you using? Use:
php -v
2) Be sure php-fpm is installed it is very important for nginx
sudo apt-get install php-fpm
3) Set correct path to php-fpm
For example, I use PHP7.0 and my path is:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
Some my projects are running on PHP5.6 and path is:
fastcgi_pass 127.0.0.1:9000;
4) Restart nginx and php-fpm (php5.6-fpm, php7.0-fpm...)
sudo service nginx restart
sudo service php5.6-fpm restart
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).
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
Okay so there have been some previous posting of this yet no solution fixes my problem.
I have site configured which is just straight up HTML, CSS & JS and I'm trying to add a wordpress site. My config for the wordpress site is as follows.
#######################
server {
listen 80;
root /usr/share/nginx/threadtheatre/wordpress;
index index.php;
server_name threadtheatre.co.uk;
access_log /var/log/nginx/thread.access.log;
error_log /var/log/nginx/thread.error.log;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
This is the error thats in my logs
"/usr/share/nginx/threadtheatre/wordpress/index.php" failed (13: Permission denied), client: 109.155.53.189, server: threadtheatre.co.uk, request: "GET / HTTP/1.1", host: "threadtheatre.co.uk"
nginx is using the nginx user and likewise for php-fpm. The nginx directory and all its sub directories have the following permissions.
drwxrwxr-x. 3 root nginx 4096 Feb 8 18:23 ..
If I browse to threadtheatre.co.uk on the web i get 404.
hope someone can help with this.
Lee.
Do you still have this problem? This explanation worked for me:
https://serverfault.com/a/170263/140684
basically nginx needs to have execution rights on every dir on the path to your app. Hope this helps.
for me this is because selinux enabled, check with
selinuxenabled && echo enabled || echo disabled
if enabled try to disable
nano /etc/sysconfig/selinux
SELINUX=disabled
then
reboot
If nginx is hosted on Fedora or RedHat , change the SELinux policy and allow nginx to serve from the path /home/path/site
chcon -R -t httpd_sys_content_t /home/path/site