【发布时间】:2019-04-29 20:55:14
【问题描述】:
我使用 Nginx 作为 Apache 的反向代理。我有一个域,假设 example.com 指向 /var/www/html/example 目录。
我想将一个子域phpmyadmin.example.com 指向一个目录/var/www/html/phpmyadmin,该目录显然不是该域目录的子目录。
我的完整配置文件/etc/nginx/sites-enabled/example如下所示。我将##### BEGIN .. 和###### END .. 之间的部分添加到我的配置文件中以尝试使其工作。
然后我通过sudo service nginx restart成功重启了NGINX,但我仍然无法访问phpmyadmin.example.com。
这是我的配置:
server {
root /var/www/html/example;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com;
access_log /var/www/html/example/access.log;
error_log /var/www/html/example/error.log;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
# 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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
##### BEGIN PHPMYADMIN CONFIG #####
server {
root /var/www/html/phpmyadmin;
index index.php index.html index.htm index.nginx-debian.html;
server_name phpmyadmin.example.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$args;
}
# 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;
}
}
###### END OF PHPMYADMIN CONFIG #####
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name example.com www.example.com
return 404; # managed by Certbot
}
【问题讨论】:
-
您的配置似乎正确。但是 sites-enabled 不是配置域的地方,所以 sites-available 是。
-
访问
http://phpmyadmin.example.com时会发生什么? -
我收到此错误消息:嗯。我们无法找到该网站。我们无法连接到服务器
phpmyadmin.example.com
标签: php nginx phpmyadmin reverse-proxy