Nginx running, but page is blank - php

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.

Related

Blank page (ssl error) when I am trying to access my website with a 4G connection?

Some of my clients are experimenting a blank page when they are trying to reach my website using there 4G internet.
By accumulating cases, I found out that it's alway a specific 4G provider: Bouygues telecom (french provider). Could be other provider, but this one is the most recurrent.
I have an Ubuntu webserver running Nginx and php5.
Sadly i can't find any nginx logs of those blank screen connexion.
When i am sharing a Bouygues 4G connexion thought my laptop, I also have a issue with a PR_CONNECT_RESET_ERROR on mozzila. Or a ERR_CONNECTION_RESET on a xiaomi phone.
Last track, i can reach my preproduction website with this 4G connexion, which have no ssl conf.
Somebody have an idear of what i am experimenting.
You will fin below my nginx conf:
server {
listen 80 default_server;
allow all;
server_name _;
return 301 https://$host$request_uri;
}server {
listen 443 default_server ssl;
allow all;
ssl on;
ssl_certificate /etc/nginx/ssl/2020_easyrenter.crt;
ssl_certificate_key /etc/nginx/ssl/easyrenter.fr.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_dhparam /etc/nginx/ssl/dhparam.pem;
ssl_prefer_server_ciphers on;
ssl_session_cache builtin:1000 shared:SSL:10m;
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains';
ssl_stapling_verify on;
resolver 8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout 10s; server_name www.easyrenter.fr easyrenter.fr 46.101.103.115;
root /home/deploy/easyrenter/current/; location = /sitemap.xml {
alias /home/deploy/easyrenter/current/sitemap.xml;
} location = /sitemaps/en/sitemap.xml {
alias /home/deploy/easyrenter/current/sitemaps/en/sitemap.xml;
} location = /sitemaps/fr/sitemap.xml {
alias /home/deploy/easyrenter/current/sitemaps/fr/sitemap.xml;
} location / {
index index.html index.php;
try_files $uri/ #handler;
expires 30d;
} location ~ \.(js|css|png|jpg|gif|ico|pdf|tiff|swf) {
try_files $uri $uri/;
expires 356d;
} location ^~ /app/ {deny all;}
location ^~ /includes/ {deny all;}
#location ^~ /lib/ {deny all;}
location ^~ /media/downloadable/ {deny all;}
location ^~ /pkginfo/ {deny all;}
location ^~ /report/config.xml {deny all;}
location ^~ /var/ {deny all;} location /var/export {
auth_basic "restricted";
auth_basic_user_file htpasswd;
autoindex on;
} location /. {
return 404;
} location #handler {
rewrite / /index.php;
}# location ~ .php {
# rewrite ^(.*.php)/ $1 last;
# } location ~ \.php$ {
if (!-e $request_filename) { rewrite / /index.php last;}
expires off;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
proxy_read_timeout 300; } #Poids max des upload files
client_max_body_size 32M; include /etc/nginx/nginx-redirection.conf;
}
I found the solution.
Bouygues 4G was forcing the IPV6 of my serveur.
At first the request page was lopping for the users using there 4G Bouygues. Guessing that it was a IPV6 issue, i activate a IPV6 on my server and i add a AAAA entry on my DNS.
Then the 4G Bouygues user had a blank page, because the IPV6 wasn't declare on my nginx conf. Here below my adds:
server {
listen 80;
**listen [::]:80;**
allow all;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 default_server ssl http2;
**listen [::]:443 default_server ssl http2;**
Hope it will help others,
Axel

NGINX access multiple sites same IP url

I would like to know how I can have several sites on Nginx and be able to access each of them with the same IP (without the domain, since I am doing tests in a laboratory locally).
I have the server on a separate PC and I access it remotely from my computer using the IP. Both are on the same LAN.
In the directory /var/www/ I have two sites 'nextcloud' and 'phpmyadmin'. I would like to be able to enter both by placing (for example) 192.168.1.14/nextcloud and 192.168.1.14/phpmyadmin. Or having any other project in the www directory.
I tried all the solutions I found, but none of them worked for me. When I enter phpmyadmin for example, it gives me to download the page instead of entering it.
Within /etc/nginx/sites-enabled I have the two files, one from nextcloud:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/nextcloud/;
index index.php index.html index.htm;
server_name localhost;
client_max_body_size 512M;
fastcgi_buffers 64 4K;
location / {
root /var/www/nextcloud;
rewrite ^ /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
And that of phpmyadmin:
server {
listen 80;
listen [::]:80;
root /var/www/phpmyadmin/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
Try creating two test folders in /var/www/ (test1 and test2), each with an index.html file inside and modifying the nginx default file, but it didn't work for me either
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
index index.html;
location / {
return 410; # Default root of site won't exist.
}
location /test1/ {
alias /var/www/test1/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
location /test2/ {
alias /var/www/test2/;
try_files $uri $uri/ =404;
# any additional configuration for non-static content
}
}
As I said, I tried different solutions. Another problem I had was that it only redirected me to nextcloud, although I put phpmyadmin in the url. And the previous one that I already mentioned, that when I enter, download the index.php. Thank you.
Sorry for my English.
Simple add nextcloud.my and phpmyadmin.my to your .hosts file and listen domain name in Nginx.
The option that you proposed can also be made to work, but it is full of bugs and difficulties can occur during the transfer to work server.

PHP not running on nginx with Debian 8

I just configured my Debian 8 server with nginx. I can browse html files. I use let's encrypt which works succesfully, also with redirecting http to https automatically.
What does not work is PHP. Also a simple info.php file with
<?php
phpinfo();
?>
does not work.
On browser client my error message is:
404 Not Found nginx/1.6.2
Nginx' error log shows this:
2018/05/29 19:22:57 [error] 1879#0: *1592 open() "/usr/share/nginx/html/info.php" failed (2: No such file or directory), client: ip_address, server: , request: "GET /info.php HTTP/1.1", host: "domain"
My nginx configuration is:
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
server_name my-server.de www.my-server.de;
return 301 https://$server_name$request_uri;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-my-server.de.conf;
include snippets/ssl-params.conf;
}
Even if i move info.php to /usr/share/nginx/html then the client browser just downloads the info.php file.
I went through all steps in this guide. But still it isn't working. So how to fix that?
You have not added in SSL listen port 443, and ssl config of let's encrypt, please comment 301 redirect, test PHP, than go for SSL configuration see https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8
I have seen you have added SSL configuration, you need fix as below nginx configuration, after redirect, PHP should be configured on 443 not on 80.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name my-server.de www.my-server.de;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-my-server.de.conf;
include snippets/ssl-params.conf;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ /.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
This is what I'm using:
upstream php {
server 127.0.0.1:9000;
server unix:/var/run/php5-fpm.sock down;
}
location ~* \.php$ {
root /var/www/html/;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 180;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_pass php;
fastcgi_index index.php;
}

Nginx always serves php-fpm site on domain1.com for any of the configured server blocks

I would like to serve two php sites and one static site on my server. Eventually I'd like to be able to add a number of further static, php or proxied sites to this nginx configuration.
At the moment, I try to serve
domain1.com (php, WordPress)
sub.domain1.com (php, phpMyAdmin)
domain2.com (static, plain HTML)
However all of the requests to any domain always end up serving domain1.com. I have since implemented SSL, hoping to eliminate the wrongly served sites, however now they have turned into redirects to https://domain1.com.
I have also tried to implement a catch-all which drops the connection (return 444) on incorrect domains, but that does exactly what it says on the package: It'll just start sending empty responses for sub.domain1.com and domain2.com. Not sure what I expected to be honest.
Furthermore I have tried to move the root directive into location blocks as can be seen in domain1.com's configuration, however this also did not help.
Additionally, I tried to put the domain in the listen 80; directives, such as listen domain2.com:80 hoping to make nginx prefer this block over the general domain1.com block. I got that inspiration from Nginx Request Processing Documentation. However, also without luck.
I would not call myself the most proficient nginx user, but on a different server which hosts multiple domains which serve proxied content from gunicorn servers, this was never an issue. Hence, I suspect the php related configuration part is what creates this problem.
The guide I used to set up my vanilla server was this DigitalOcean guide. However, the server I am actually using is an Amazon EC2 t2.micro instance with all necessary ports opened in the security group. I am also using Ubuntu 14.04 LTS. Nginx is running as root, worker processes as www-data. The permissions are all set up like for domain1.com which is served without a problem. All the domains point to the IP address of the EC2 instance.
Thank you for helping!
This is my nginx configuration for each of the domains.
domain1.com
server {
listen 80;
server_name domain1.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name domain1.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
index index.php index.html index.htm;
client_max_body_size 64M;
location / {
root /usr/share/nginx/html/domain1.com/public;
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html/domain1.com/public;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sub.domain1.com
server {
listen 80;
server_name sub.domain1.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name sub.domain1.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/sub.domain1.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sub.domain1.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
index index.php index.html index.htm;
server_name sub.domain1.com;
client_max_body_size 64M;
location / {
try_files $uri $uri/ =404;
root /var/www/sub.domain1.com;
}
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/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
domain2.com
server {
listen 80;
server_name domain2.com www.domain2.com;
root /var/www/domain2.com/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}

NGINX change phpMyAdmin port within a location block

I have my phpMyAdmin setup as follows. This is within the server block of the default in sites-available and sites-enabled.
How can I change the port to say 8003 within the location block or somewhere without affecting the function of the port 80?
server{
listen 80; ## listen for ipv4
listen [::]:80 default ipv6only=on; ## listen for ipv6
[..........]
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
[..........]
}
You can't set a port in a location block. It wouldn't make sense because the client is connected already when a location is processed. You can make a new server block though, listening on the port you want, and put the location-block in question in the new server block.

Categories