ubuntu 16.04 nginx change phpmyadmin url not working - nginx

Ubuntu 16.04.5 LTS Xenial 4.18.8-x86_64-linode117
nginx version: nginx/1.10.3 (Ubuntu)
php v7.0.32-0ubuntu0.16.04.1`
/etc/nginx/sites-available/default
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
No symlink at /var/www/html
Worx well....
But I can't seem to figure out how to change phpmyadmin url.
Tried creating a symlink whatever ->/usr/share/phpmyadmin or whatever ->/usr/share/phpmyadmin/ under /var/www/htmldoes not work,
Even if I change /etc/nginx/sites-available/default to:
location /whatever {
root /usr/share/phpmyadmin/;
Created a symlink as mentioned above, restarted both nginx & php7.0-fpm still the new URL tried to download the page...
Looked up different resources on the net but they dont help:
digitalocean's guide
devanswers guide
As well as other here on SO but couldn't find a solution.
Ideas??
UPDATE
By Richard Smith's remark
location /whatever {
alias /usr/share/phpmyadmin;
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^ /phpmyadmin/index.php last; }
# Secure phpMyAdmin Instance
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/.your_pass_file;
client_max_body_size 68M;
location ~ ^/phpmyadmin/(.+\.php)$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
alias /usr/share/phpmyadmin;
}
}

Try:
location ^~ /whatever {
alias /usr/share/phpmyadmin;
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^ /whatever/index.php last; }
# Secure phpMyAdmin Instance
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/.your_pass_file;
client_max_body_size 68M;
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
You need to use /whatever/index.php in the rewrite statement. The nested location blocks only need to match the end of the URI. The ^~ modifier avoids conflicts with other regular expression location blocks at the server block level. Use $request_filename in the SCRIPT_FILENAME. Your last nested location block appears to perform no function.
Avoid try_files with alias due to this issue. See this caution on the use of if.

Related

Typo3 Installation on CentOS 7 with php7 and nginx

I'm trying to install Typo3 on my CentOS server.
I want to run it with php7 and nginx.
If i do a index.php with phpinfo it works. after i change the index of to the index from Typo3 it doesent work anymore.
http://baddog.me/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/typo3/sysext/install/Start/Install.php
my Nginx config:
server {
server_name baddog.me;
listen 80;
root /var/www/typo3/htdocs;
location ~* \.(?:jpg|css|js|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|json|woff)$ {
expires 1M;
add_header Cache-Control "public";
}
error_page 500 501 502 503 504 /500.html;
location = /500 {
return 500;
}
location /500.html {
internal;
}
location /robots.txt {
}
location /favicon.ico {
}
location ~ \.png {
try_files $uri =404;
}
location / {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/typo3/htdocs/index.php;
include fastcgi_params;
}
}
i changed some parameters in the php.ini.
Sorry for my bad english. I hope for help :) ty
Why do you hardcode the index.php as only file that is passed to PHP?
server {
listen *:8080;
root /var/www/html;
index index.php index.html index.htm;
server_name php7;
location / {
try_files $uri $uri/ =404;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include fastcgi_params;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
Check port (listen), root and server_name and adopt them as needed.
Also make sure that all files have the correct security label (selinux), thus run $ restorecon -rv /var/www/html.

Nginx configuration for a wordpress blog in a subfolder of magento root

I have installed a Magento extension to have a wordpress blog integrated with Magento.
Basically, the WP is in a subdirectory of the Magento root. I want to create multiple sites with subdirectories but I can't make it work due to the nginx configuration.
Wordpress is in his /wp subdirectory (http://example.com/wp/wp-admin/) and the others sites are accessible from http://example.com/wp/ca/wp-admin/ and http://example.com/wp/en/wp-admin/
Here is whats I got so far :
server
{
server_name dev.example.com;
access_log /var/log/nginx/example.access.log;-
error_log /var/log/nginx/example.error.log;
root /var/www/example;
location ^~ /wp {
index index.php index.html index.htm;
try_files $uri $uri/ /wp/index.php?q=$uri&$args;
# Multisite
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/wp(/[^/]+)?(/wp-.*) /wp$2 last;
rewrite ^/wp(/[^/]+)?(/.*\.php)$ /wp$2 last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
set $mage_developer true;
set $mage_code es;
set $mage_type store;
include snippets.d/magento-site;-
}
and in snippets.d/magento-site :
# Serve static pages directly,
# otherwise pass the URI to Magento's front handler
location / {
index index.php;
try_files $uri $uri/ #handler;
expires 30d;-
}
# Disable .htaccess and other hidden files
location /. {
return 404;
}
# Allow admins only to view export folder
location /var/export/ {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
autoindex on;
}
# These locations would be hidden by .htaccess normally
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; }
# Magento uses a common front handler
location #handler {
rewrite / /index.php;
}
# Forward paths like /js/index.php/x.js to relevant handler
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
# Execute PHP scripts
location ~ .php$ {
# Catch 404s that try_files miss
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param MAGE_RUN_CODE $mage_code;
fastcgi_param MAGE_RUN_TYPE $mage_type;
fastcgi_ignore_client_abort on;
fastcgi_read_timeout 900s; # 15 minutes
}
Thanks for your help.
Wanted to pass along a full conf file for anyone who needs to configure this. Please keep in mind, many file paths are unique your your server configuration.
Please note, you'll need to adjust the following parameters based on file paths on your server:
server_name domain.com www.domain.com;
ssl_certificate /sslpath/domain.com.crt;
ssl_certificate_key /sslpath/domain.com.key;
root /webrootpath/domain.com;
rewrite ^/blogpath(.*) /blogpath/index.php?q=$1;
location ^~ /blogpath {
error_log /data/log/nginx/domain.com_error.log;
access_log /data/log/nginx/domain.com_access.log;
Here is the full nginx conf file:
server {
listen 80;
server_name domain.com www.domain.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name domain.com www.domain.com;
ssl on;
ssl_certificate /sslpath/domain.com.crt;
ssl_certificate_key /sslpath/domain.com.key;
ssl_session_timeout 30m;
root /webrootpath/domain.com;
index index.php;
location / {
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
location #wp {
rewrite ^/blogpath(.*) /blogpath/index.php?q=$1;
}
location ^~ /blogpath {
root /webrootpath/domain.com;
index index.php index.html index.htm;
try_files $uri $uri/ #wp;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
location ~ ^/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /var/export/ { internal; }
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 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
error_log /data/log/nginx/domain.com_error.log;
access_log /data/log/nginx/domain.com_access.log;
}
Well, in the end, it works passing all request to the blog to Apache and creating the site in the virtual hosts corresponding.
location ~ ^/blog {
proxy_pass http://apache:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 6000s;
}
If someone succeed to make it work with Nginx only, I'm looking forward to his answer :)
Why run Apache? Doesn't make sense to run 2 webservers.
Try adding this to your nginx conf.
location #wp {
rewrite ^/wp(.*) /wp/index.php?q=$1;
}
location ^~ /wp {
root /var/www/example;
index index.php index.html index.htm;
try_files $uri $uri/ #wp;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}

PhpMyAdmin and nginx configuration , get phpmyadmin after IP

What i'm trying to do is to access phpmyadmin from IP/phpmyadmin
I have edited the default conficuration file in the Site-available directory
my configuration is :
server {
location /phpmyadmin {
root /usr/share/;
index index.php;
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/ {
alias /usr/share/phpmyadmin/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
But when I go to IP/phpmyadmin
it redirects me to the maini index file which we see the Welcome to nginx! message
Any help would be great !
I found out what was wrong!
I just needed to add the symbolic link
sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/www
Actually you needed to add the server_name with your IP, and maybe also disable the default server, what you did is just tricking nginx.

Nginx auth_basic and rewrite in subdirectory does not work

I'm trying to add a project to a subfolder of existing webserver with Nginx. Here's my simple config:
server {
listen 80 default_server;
server_name localhost;
root /var/www;
[...]
location = /my-project { return 301 /my-project/; }
location /my-project/ {
alias /var/www/my-project/web/;
index index.php;
location ~ /[^/]+/control(/|$) {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
if (-f $request_filename) { break; }
rewrite ^(.*)$ /my-project/index.php last;
}
if (-f $request_filename) { break; }
rewrite ^ /my-project/index.php last;
location ~ ^/[^/]+/index\.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}
}
Because there is an rewrite directive inside /control location block, the auth_basic never gets triggered, because Nginx executes rewrites before authentication. In which way should I modify the config, that auth does work?
PS: try_files doesn't seem to work, because it serves files from root (/) webfolder!? When I replace the if and following rewrite with try_files $uri /my-project/index.php?$query_string; I get a 404, because Nginx tries to serve the file /var/wwwindex.php (have a look at missing slash and the root folder /var/www instead of alias).
EDIT 18.09.2013:
As VBart suggests I'm using now the following configuration to get authentication to work
location ~ ^/(?<dir>my-project)(?<path>/.*)$ {
root /var/www/$dir/web;
location ~ ^/[^/]+/control(/|$) {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
try_files $path /$dir/index.php?$query_string;
}
try_files $path /$dir/index.php?$query_string;
location ~ ^/[^/]+/index\.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgi.sock;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
}
Use:
error_page 404 =200 /my-project/index.php;
instead of ugly rewrites:
if (-f $request_filename) { break; }
rewrite ^(.*)$ /my-project/index.php last;
Reference:
http://nginx.org/r/error_page
http://wiki.nginx.org/IfIsEvil
http://wiki.nginx.org/Pitfalls
P.S. try_files doesn't work with alias because of bug: http://trac.nginx.org/nginx/ticket/97, but you can replace alias with root directive: http://nginx.org/r/root

nginx settings location mis-downloading

I'm setting up nginx with php5-fpm on Ubuntu 12.04LTS for wordpress and phpMyAdmin.
My phpMyAdmin locates in/var/www/phpMyAdmin, wordpress in /home/user/workspace/wordpress, MySQL at /var/run/mysqld/mysqld.sock
I want to map / to wordpress, /phpmyadmin to phpMyAdmin, so how can I achieve this??
Wordpress seemed OK, but when accessing /phpmyadmin, the browser "downloads" the request as files...??
This is my current nginx.conf:
server {
listen 8000;
root /home/user/workspace/wordpress;
index index.html index.htm index.php;\
location ~* /phpmyadmin { #TODO: shall here be a tailing slash??
#TODO: root or alias???
}
location ~ \..*/.*\.php$ {
return 403;
}
location / {
#TODO: show the following line be un-commented??
#try_files $uri $uri/ /index.php?q=$uri&$args;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;#TODO: could this being removed??
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
#FIXME: and how to block all access to /home/user/workspace/wordpress/server.d/*
#This doesn't work??
location /sever\.d {
autoindex on;
deny all;
}
And, what permission should I set for both the directory wordpress/ and phpMyAdmin/ if all the servers are running as www-data:www-data??
Currently I set them as 755 user:www-data, is that correct??
I haven't set up server under linux yet, I was using those servers under WinXP, so I'm trying.
in you between location add this
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;
}
anywhere between
also
your missing a server name. type in a server_name example.com;

Resources