我configuration了我的nginx服务器+ php。 除了phpmyadmin以外,其他所有的东西都可以正常工作。
我GOOGLE了很多,发现一些别名技巧,但他们没有对我工作。
这很好:
location ~ ^/ololo/(.*\.php)$ { alias $root_path/img/$1; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; } location /ololo/ { alias $root_path/img/; index index.php; }
有我的网站pathimg
目录,当我请求sitename/ololo/
或sitename/ololo/index.php
一切都很好。
但那:
location ~ ^/myadmin/(.*\.php)$ { alias /usr/share/phpmyadmin/$1; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; } location /myadmin/ { alias /usr/share/phpmyadmin/; index index.php; }
将无法正常工作!
当我试图请求mysite/myadmin/
或mysite/myadmin/index.php
服务器抛出我
没有指定input文件。
错误信息。 在/usr/share/phpmyadmin/
都是.php
文件。
我的nginx.conf
什么问题?
好吧,根据我的理解你的回答我正在修改这个答案,添加到您的主服务器,它应该工作。
location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; } }
编辑 :
好,所以一个下来的vode让我再次看看这个,这已经有一段时间了,因为我已经写了这个答案,我应该说这不是如何编写配置文件如果是今天,这是配置我会用。
location /phpmyadmin { index index.php index.htm; root /usr/share; } location ~* \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; }
如果你想使用别名,那么用这个替换phpmyadmin
块
location /phpmyadmin { index index.php index.htm; alias /usr/share/phpmyadmin; }
注意:如果你的服务器块已经包含index
那么你不需要在phpmyadmin
块中重新定义它。
阅读评论的顺序必须是确切的,如果仍然错误阅读error.log
### first define phpmyadmin static files location ~ ^/phpmyadmin/.*\.(jpg|jpeg|gif|png|ico|css|js|woff|ttf)$ { root /usr/share/; expires max; #log_not_found off; } ### then your public_html static file location ~* \.(jpg|jpeg|gif|png|ico|css|js|woff|ttf)$ { root /path/public_html; expires max; #log_not_found off; }
因为phpmyadmin路径在public_html之外,所以你需要try_files将斜杠“/”重定向到“/index.php”
location /phpmyadmin { try_files $uri $uri/ /phpmyadmin/index.php?$args; }
现在是最后一个,fastcgi
### Define phpmyadmin PHP files location ~ ^/phpmyadmin/(.*)\.php$ { ## optional, try uncomment if error #root /usr/share/phpmyadmin/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/$fastcgi_script_name; include fastcgi_params; } ### then your public_html files location ~ \.php$ { ##optional, try uncomment if error #root /path/public_html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /path/public_html/$fastcgi_script_name; include fastcgi_params; }
现在你可以访问http://yoursite/phpmyadmin
这是我的配置:
location /phpmyadmin { alias /usr/share/phpmyadmin; index index.php; location ~ /([^/]+\.php)$ { try_files /$1 =404; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; location ~ /phpmyadmin/js/([^/]+\.php)$ { try_files /phpmyadmin/js/$1 =404; fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } }