403 Forbidden error in phpmyadmin - nginx

I am trying to run rails application on ubuntu14.04 , after installing phpMyAdmin , nginx unable to load phpmyadmin
nginx error log
nginx/html/phpmyadmin/" is forbidden

Within your Nginx conf.d folder (For Ubuntu location is /etc/nginx/conf.d) create one default.conf file if not already available and put the below code block. Sample conf file you can check here. You can use the server block to begin with.
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;
}

Related

Magento2 NGINX run external PHP scripts

Magento2 site setup on AWS with NGINX. Site working fine.
I am trying to allow PHP scripts to run if they are in a specific folder, but they always 404.
I have placed the following inside my nginx config file, and restarted nginx:
location /custom_tests/ {
location ~* \.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_buffers 1024 4k;
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I am trying to access scripts that are in sub directories of the 'custom_tests' folder, but i have also added an index.php in the 'custom_tests' folder itself. All i get is 404 not found.
I have the above NGINX entry just above the following block in the config file:
# PHP entry point for main application
location ~ (index|get|static|report|404|503|health_check)\.php$ {

Redirect everything but few pages in Nginx

I have a subdomain leading to website hosted in subfolder containing :
a subfolder named r, inside of which I have my CSS and other resources files (you'll understand why I have this folder later)
few files such as privacy-policy.php, imprint.php,...
a script index.php
I want that the user type http://www.example.com/STRING, he got served http://www.example.com/index.php?code=STRING except when this would lead to an existing page when adding back the .php(i.e. http://www.example.com/privacy-policy, http://www.example.com/imprint)
Right now, my nginx conf file gives this
location /subfolder/ {
try_files $uri $uri/ $uri.php index.php?code=$uri;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
location /subfolder/r/ {
try_files $uri $uri/ =404;
}
}
The subfolder r has been created so that the static files are not processed by PHP.
This works well for the static files inside the r subfolder, also works well for the imprint.php type, but it does not work for the redirect to index.php?code=$uri.
Why is that?

install postfixadmin in a subfolder of a domain in nginx

I need to install postfixadmin as a subfolder of a domain hosted in nginx.
In other words, I'm trying to access postfixadmin using http://example.com/postfixadmin
Physically, the contents of the sites are stored this way:
example.com site in /var/www/example
Postfixadmin files in /var/www/postfixadmin
I've tried adding this within the server section of example.com:
location ~ /posfixadmin/ {
root /var/www;
index index.php;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
The above works partially, php scripts are executed correctly, but css and image files found under /var/www/postfixadmin/css and /var/www/postfixadmin/images are not loaded.
I've checked at the generated html code and the links to css and image files in postfixadmin are called using relative paths, like this:
href="css/default.css"
I think nginx tries to get the css files from http://example.com/css instead of http://example.com/postfixadmin/css, that's why it's failing, I've tried something like this:
location /postfixadmin/css/ {
root /var/www/postfixadmin;
}
but the above doesn't work.
Any idea about how to fix this? Thanks in advance!
I know it's an old topic, but still: do not use "root" in a "location" block. Source: https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
This works for me at the moment with the current PostfixAdmin 3.2 (which moved all the public facing stuff into the "public" subdirectory). Mind that I have defined the fastcgi_pass elsewhere, so this bit is not directly applicable.
location /postfixadmin {
alias /usr/local/www/postfixadmin/public;
location ~ ^(.+\.php)(.*)$ {
fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_read_timeout 180;
fastcgi_buffers 4 256k;
fastcgi_buffer_size 128k;
}
location ~ \.php {
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass php;
fastcgi_index index.php;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

Nginx white page with no error

I'm new to nginx. I'm trying to use kubernetes with nginx. But I get a blank page and no error... what can I do ?
Here my configuration :
server {
listen 80;
root /var/www/project/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
#internal;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
Edit :
I run it in a docker-compose, now I get this when I launch :
web_1 | * Restarting PHP5 FastCGI Process Manager php5-fpm
Edit 2
connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file
or directory) while connecting to upstream

fastcgi - passing information to scripts

I`m new with nginx and I dont know even what should I look for. My task is to force (I think it is) fastcgi to pass information (PATH_INFO) to the scripts. I have been told that I should add something in block after location ~ .php$ . Adding before fastcgi_pass xxx;
fastcgi_param PATH_INFO $fastcgi_path_info;
would made that happened ?
My location part config file looks like that:
location ~ ^/backend\.php/(.*)$ {
try_files $uri /backend.php?$1;
}
location ~ \.php$ {
# Zero-day exploit defense.
# http://forum.nginx.org/read.php?2,88845,page=3
# Won't work properly (404 error) if the file is not stored on this server, which is entirely possible with php-fpm/php-fcgi.
# Comment the 'try_files' line out if you set up php-fpm/php-fcgi on another machine. And then cross your fingers that you won't get hacked.
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass xxx;
}

Resources