Nginx not excuting php - 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/.

Related

502 Error not understood on nginx server used with php [duplicate]

This question already has answers here:
upstream sent too big header while reading response header from upstream
(16 answers)
Closed last year.
I'm currently trying to switch from an Apache server to using nginx to be load resistant.
But I came across an error that I can not solve and I would be happy for your help,
so:
Most pages (php) work smoothly,
Unexpectedly certain pages when I browse to them I get a 502 error
Quote the error from the error.log logs
2022/01/25 18:51:57 [error] 848#848: *4 upstream sent too big header while reading response header from upstream, client: 147.234.64.35, server: XXXX.com, request: "GET /XXX.php?XXX=true&XXX=no&XXX= HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "XXX.com"
But what I do not understand most is that when I enable error output by adding the value "ini_set ('display_errors', 1);" At the top of the code, it works smoothly without a 502 error
This is defined for me in the file / etc / nginx / sites-available / default
server {
server_name domain.com;
root /var/www/html;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.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 = domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name domain.com;
return 404; # managed by Certbot
}
I would appreciate any assistance or preparation
Thanks
Try to add:
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
or (if you use proxy_pass):
proxy_buffer_size 128k;
proxy_buffers 16 256k;
proxy_busy_buffers_size 256k;
If necessary change the values ;)

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 conflicting server name, but different ports

My plan was to do a simple Nginx setup with redirections for URLs without the subdomain "www" and without port 443. The problem is that I get the following warning as output:
nginx: [warn] conflicting server name "domain.de" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "domain.de" on 0.0.0.0:80, ignored
I don't really get why there is a conflicting server name if the domains are on separate ports. Is there a workaround of do I miss something?
server {
server_name www.domain.de;
root /var/www/folder/;
index index.php;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.de/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = www.domain.de) {
return 301 https://www.domain.de$request_uri;
}
if ($host = domain.de) {
return 301 https://www.domain.de$request_uri;
}
listen 80;
server_name www.domain.de domain.de;
return 404;
}
server {
if ($host = domain.de.de) {
return 301 https://www.domain.de$request_uri;
}
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/domain.de.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.de.de/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
server_name domain.de;
return 404;
}
Best regards
For some reason certbot created a redirect in the default config. Never had this issue before. After I removed the duplicated code it worked.

Laravel giving 502 bad gateway in nginx

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.

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.

Categories