大网数据广告活动
服务器运维问答

Accessing phpmyadmin in Nginx directly from IP address (without a subdomain)

· 52CE 我爱测

In an Ubuntu 16.04 Nginx environment which has some sites working fine, I've installed phpmyadmin: cd /var/www/html wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip find ./ -type f -iname '*phpmyadmin…

问题原文

原帖链接 · Arcticooling · CC BY-SA 3.0

In an Ubuntu 16.04 Nginx environment which has some sites working fine, I've installed phpmyadmin:

cd /var/www/html
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
find ./ -type f -iname '*phpmyadmin*.zip' -exec unzip {} \;
find ./ -type d -iname 'phpmyadmin-*' -exec mv {} phpmyadmin \;

I then tried to access it from my browser via ip_address/phpmyadmin, yet I got a 404 in one of my sites.

I thought this is caused from lacking a webapp conf so I created one.

nano /etc/nginx/sites-available/phpmyadmin.conf:

server {
    root /var/www/html/phpmyadmin/;
    server_name phpmyadmin;

    location / {
        index index.php index.html index.htm fastcgi_index;
        try_files $uri $uri =404 $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    listen 80;
}

Then

ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/
systemctl restart nginx.service

Yet, the problem persist.

The logs specify only this error:

2018/01/01 03:02:25 [emerg] 21959#21959: unknown directive "/var/www/html/phpmyadmin/" in /etc/nginx/sites-enabled/phpmyadmin.conf:2

I basically didn't change nginx.conf and rely on its native directives.

I have consulted an Nginx sysadmin how suggested me to use a subdomain but I prefer accessing it directly from IP address.

已采纳解答

原帖链接 · Richard Smith · CC BY-SA 3.0

The server_name should contain the name(s) used to access the server. To access a server by IP address, it should contain the IP address.

For example:

server_name 192.0.2.1;

See this document for more.

But first you need to fix that error - I don't know why you are getting an unknown directive error from your root statement. Have you introduced a typo?

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-01-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。