Laravel giving 502 bad gateway in nginx - php

I have reloaded my server configuration to match the one provided on Laravel. When I do php --ini I can see my PHP version is 7.0 so I made the alterations to use 7.0.
My server config looks like this:
server {
server_name exoscape.co.uk;
root /var/www/html/exoscape/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/exoscape.co.uk/fullchain.pem; # manag$
ssl_certificate_key /etc/letsencrypt/live/exoscape.co.uk/privkey.pem; # man$
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = exoscape.co.uk) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name exoscape.co.uk;
return 404; # managed by Certbot
}
I have tried to ensure that the dir is chmod correctly by doing:
sudo chown -R www-data:www-data /var/www/html/exoscape/
sudo chmod -R 755 /var/www/html/exoscape/
But I still receive 502 Bad Gateway when I visit my domain. I am using nginx/1.15.12. Any help would be appreciated.

Related

Nginx running, but page is blank

I'm trying to configure a MunkiReport (https://github.com/munkireport/munkireport-php) site on an Ubuntu server hosted in DigitalOcean. I have PHP and MySQL installed and configured. When I navigate to my webroot, I get a successful message back from nginx.
My webroot is /usr/share/nginx/html and I'm using /usr/local as my repo for both Munki and MunkiReport. I put a symlink for the /usr/local/report/public folder into /usr/share/nginx/html.
Here is my nginx configuration (/etc/nginx/sites-enabled/default) file:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name example.com;
location /report {
alias /usr/share/nginx/html/public;
autoindex off;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
location /munki_repo/ {
alias /usr/local/munki_repo/;
autoindex off;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
}
}
I have an .env file at the root of my MunkiReport folder which contains the configuration information (MySQL database connection) inside of it.
When I navigate to the https://example.com/report location, nothing loads. The console doesn't show any errors either, it's just blank.

How do I enable Adminer skins on a LEMP stack?

After much wailing and gnashing of teeth, I've got adminer up and running on my Ubuntu 20.04 server running a LEMP stack. The database management seems to work fine, but it looks ugly as sin, without even the default skin on (see screenshot). That would be fine except that it makes it hard to use the program effectively.
I tried putting a new adminer.css file into the directory with adminer.php (see second screenshot), but it didn't work. I've also gone down a lot of rabbit holes here and on sourceforge with no luck. Most of them point to some issue with .css serving through https:// but I don't know enough to make sense of what's happening or not happening.
So I turn to you, great hive mind. What else can I try? Below is my nginx server block for reference:
server {
server_name adminer.WEBSITE.COM;
root /var/www/html/adminer;
index index.php index.html index.htm index.nginx-debian.html
access_log /var/log/nginx/adminer.access.log;
error_log /var/log/nginx/adminer.error.log;
location / {
try_files $uri $uri/ /index.php?$args;
include /etc/nginx/mime.types;
}
location ~\.php$ {
auth_basic "Please enter username and password";
auth_basic_user_file /etc/nginx/PASSWORDFILE;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/adminer.WEBSITE.COM/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/adminer.WEBSITE.COM/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = adminer.WEBSITE.COM) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name adminer.WEBSITE.COM;
listen 80;
return 404; # managed by Certbot
}

Nginx not excuting php

I am using Nginx for a couple of websites. First time user of it and not that happy (Apache will not work in my case). I am trying to use PHP for a new project that requires it. I have PHP 7.3 FPM. To test, phpinfo(); does work however when adding this project (openCAD), index.php seems to be blank.
I tried putting on MyBB to see if that executes and it simply does not, just a blank page.
Here is my nginx config
server {
root /var/www/mywebsite.com/;
index index.php index.html index.htm index.nginx-debian.html;
server_name mywebsite.com www.mywebsite.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}server {
if ($host = www.mywebsite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mywebsite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name mywebsite.com www.mywebsite.com;
return 404; # managed by Certbot
}
server {
if ($host = www.appeal.mywebsite.com) {
return 301 https://mywebsite.com/appeal;
} # managed by Certbot
if ($host = appeal.mywebsite.com) {
return 301 https://mywebsite.com/appeal;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name www.appeal.mywebsite.com appeal.mywebsite.com;
return 404; # managed by Certbot
}
server {
if ($host = www.cad.mywebsite.com) {
return 301 https://mywebsite.com/cad;
} # managed by Certbot
if ($host = cad.mywebsite.com) {
return 301 https://mywebsite.com/cad;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name www.cad.mywebsite.com cad.mywebsite.com;
return 404; # managed by Certbot
}
Here is the error log for trying to access MyBB
2019/08/20 15:48:11 [error] 23516#23516: *71 FastCGI sent in stderr: "PHP message: PHP Warning: require_once(/var/www/mywebsite.com/php/inc/init.php): failed to open stream: No such file or directory in /var/www/mywebsite.com/php/global.php on line 20PHP message: PHP Fatal error: require_once(): Failed opening required '/var/www/mywebsite.com/php/inc/init.php' (include_path='.:/usr/share/php') in /var/www/mywebsite.com/php/global.php on line 20" while reading response header from upstream, client: 70.44.50.53, server: mywebsite.com, request: "GET /php/index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "mywebsite.com"
Based on your error log, mybb is trying to find its files in /var/www/mywebsite.com/php/, but your root is set to /var/www/mywebsite.com/. So it looks like you didn't set it up properly. If you keep your root as is, you need to ensure that mybb's folders like inc, admin, etc. are subdirectories of /var/www/mywebsite.com/.

when i add another php site ,this site was redirected to the other php site,i didn't write the redirect .conf file. what happend?

when i add another nginx-php site,this site was redirected to another php site,i didn't write the redirect in .conf file. what happend?
this is my new site : y2b.casvot.com
site above was redirected to this domain : www.casvot.com
//=======================my nginx config file=================
//
//You should look at the following URL's in order to grasp a solid understanding
//of Nginx configuration files in order to fully unleash the power of Nginx.
//http://wiki.nginx.org/Pitfalls
//http://wiki.nginx.org/QuickStart
//http://wiki.nginx.org/Configuration
//Generally, you will want to move this file somewhere, and start with a clean
//file but keep this around for reference. Or just disable in sites-enabled.
// Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
// Default server configuration
//================================================
server {
// SSL configuration
//
// listen 443 ssl default_server;
//listen [::]:443 ssl default_server;
// Note: You should disable gzip for SSL traffic.
// See: https://bugs.debian.org/773332
// Read up on ssl_ciphers to ensure a secure configuration.
//See: https://bugs.debian.org/765782
//Self signed certs generated by the ssl-cert package
//Don't use them in a production server!
//include snippets/snakeoil.conf;
root /home/casvot;
//Add index.php to the list if you are using PHP
// Index file path
index index.php index.html index.htm index.nginx-debian.html;
server_name casvot.com www.casvot.com;
location / {
//First attempt to serve request as file, then
// as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
//pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /home/casvot/;
include snippets/fastcgi-php.conf;
// With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
//SSL configuration
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.casvot.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.casvot.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
//Virtual Host configuration for example.com
//
// You can move that to a different file under sites-available/ and symlink that
//to sites-enabled/ to enable it.
server{
listen 80;
root /home/;
index index.php index.html index.htm ;
server_name y2b.casvot.com;
location / {
// First attempt to serve request as file, then
// as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ \.php$ {
root /home;
include snippets/fastcgi-php.conf;
// With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
server {
if ($host = www.casvot.com) {
return 301 https://$host$request_uri;
} //managed by Certbot
if ($host = casvot.com) {
return 301 https://$host$request_uri;
} // managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name casvot.com www.casvot.com;
return 404; //# managed by Certbot
}
/home directory:
An issue doesn't stick out at me, but is it possible that your server and your ISP support IPv6? Maybe it's connecting via IPv6 and www.casvot.com is the only vhost listening. I don't see a listen [::]:80; for y2b.casvot.com, but I see it for the other.

Nginx app entrence forbidden although DB and CMS synced and DR dir permissions set

On Ubuntu 16.04 with Bash I've established LEMP and I can't access a WordPress app from browser although DB data is according (as I recall), and document root app dir has the right permissions (see below).
Nginx conf
nginx.conf (all default).
nginx default (all default).
Nginx app conf (seven first lines are mine - the rest is Certbot).
WordPress app wp-config.php
This is the only part I changed in wp-config.php:
define('DB_NAME', 'example.com');
define('DB_USER', 'example.com');
define('DB_PASSWORD', 'example.password');
My resets before testing
chown -R www-data:www-data /var/www/html/
chmod -R a-x,a=rX,u+w /var/www/html/
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
Nginx logs
I checked all three Nginx logs (-t,access and error). The first two logs output no error, but error outputs this:
directory index of "/var/www/html/example.com/" is forbidden
My question
Why is the entrance forbidden, given the above data? What I miss?
Notes:
This problem is unique to the WordPress app. It doesn't happen with the non-HTTPS, PHPmyadmin app.
The DB user and the DB name of the WordPress app are identical to one another and also identical to the app's dir name.
The server root at your Nginxapp.conf should be:
root /var/www/html;
Not:
root /var/www/html/example.com/;
BTW, this setting has been defined in the Nginx virtual machine default.conf, it is kind of redundant to redefine it again at the app conf file.
Update
With your comment of not working after changing the root to root /var/www/html;, I further check your setting, and notice that you do not have a location directive for handling the root directory, try to change this line in your virtual host setting from:
try_files $uri $uri/ =404;
to:
location / {
try_files $uri $uri/ /index.php?$args;
}
I was able to solve it with this conf:
server {
root /var/www/html/judith-law.co.il;
server_name judith-law.co.il www.judith-law.co.il;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff|pdf)$ {
expires 365d;
}
# managed by Certbot
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
return 404; # managed by Certbot
}

Categories