我有一个安装了 Ubuntu 20.04 和 LAMP 的 VPS 设置。然后我可以通过 访问 phpmyadmin <ip_address>/phpmyadmin
。
后来我通过添加文件启用virtualhost
了,我可以通过以下方式访问我启用的网站/etc/apache2/sites-available/
.conf
<ip_address>
但 <ip_address>/phpmyadmin
现在出现 404。据我了解,这是因为所有请求都指向我启用的站点。由于我想同时访问 phpmyadmin 和 mysite,我尝试了几种.conf
文件更改组合,这些组合是我从 Google 获得的搜索结果中建议的。但都没有奏效。尝试的三种配置如下。
添加别名
<VirtualHost *:80>
ServerAdmin john@ubuntu
ErrorLog ${APACHE_LOG_DIR}/cpapp-error.log
CustomLog ${APACHE_LOG_DIR}/cpapp-access.log combined
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
</Directory>
<Location />
ProxyPass unix:/home/john/cpapp/cpapp.sock|http://127.0.0.1/
ProxyPassReverse unix:/home/john/cpapp/cpapp.sock|http://127.0.0.1/
</Location>
</VirtualHost>
创建两个虚拟主机
<VirtualHost *:80>
ServerAdmin john@ubuntu
ErrorLog ${APACHE_LOG_DIR}/cpapp-error.log
CustomLog ${APACHE_LOG_DIR}/cpapp-access.log combined
<Location />
ProxyPass unix:/home/john/cpapp/cpapp.sock|http://127.0.0.1/
ProxyPassReverse unix:/home/john/cpapp/cpapp.sock|http://127.0.0.1/
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
将我的网站限制为特定的 URL 路径.conf
-重新加载 apache2 时出现语法错误
<VirtualHost *:80>
ServerAdmin john@ubuntu
ErrorLog ${APACHE_LOG_DIR}/cpapp-error.log
CustomLog ${APACHE_LOG_DIR}/cpapp-access.log combined
<Location />
ProxyPass /mysite/ unix:/home/john/cpapp/cpapp.sock|http://127.0.0.1/
ProxyPassReverse /mysite/ unix:/home/john/cpapp/cpapp.sock|http://127.0.0.1/
</Location>
DocumentRoot /var/www/html
</VirtualHost>
有人能指出我哪里做错了吗?
配置/etc/apache2/conf-available/phpmyadmin.conf
# phpMyAdmin default Apache configuration
Alias /phpmyadmin /usr/share/phpmyadmin
<Directory /usr/share/phpmyadmin>
Options SymLinksIfOwnerMatch
DirectoryIndex index.php
# limit libapache2-mod-php to files and directories necessary by pma
<IfModule mod_php7.c>
php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/:/usr/share/php>
</IfModule>
</Directory>
# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
Require all denied
</Directory>
答案1
安装 phpMyAdmin 时通常会附带 Apache 的配置文件 - /etc/apache2/conf.d/phpmyadmin.conf
。如果不存在此文件,请尝试使用以下命令启用它:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo systemctl restart apaache2