NOTE: It turned out that there wasn't any problem at all. See comment for detail.
I've just got fresh instance from Oracle Cloud, Ubuntu 20.04 Minimized. Since I am trying to run DokuWiki on this instance, I've installed these packages:
sudo apt install net-tools lsof wget nano
sudo apt install php7.4-fpm php7.4-xml php7.4-mbstring imagemagick nginx certbot python3-certbot-nginx
I've never touched nginx.conf
in /etc/nginx
but deleted default
symlink in /etc/sites-enabled
and put my own conf file in /etc/nginx/conf.d
with name example.com.conf
(real name is redacted though)
server {
listen 80 default_server;
server_name example.com;
root /var/www/dokuwiki;
index index.php index.html;
location / {
try_files $uri $uri/ @dokuwiki;
}
location @dokuwiki {
rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
rewrite ^/(.*) /doku.php?id=$1&$args last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /(conf|bin|inc|vendor)/ {
deny all;
}
location ~ /data/ {
internal;
}
}
and of course, /var/www/dokuwiki
is owned by www-data
(both user and group) with this command:
sudo chown -R www-data:www-data /var/www/dokuwiki
The problem is, I can't reach to my website. when I type nginx
in terminal, it screams like this:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
But, I've checked there is no apache2
-like stuff and no other process listening to port 80.
root@redacted:~# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1296 root 6u IPv4 32966 0t0 TCP *:http (LISTEN)
nginx 1297 www-data 6u IPv4 32966 0t0 TCP *:http (LISTEN)
nginx 1298 www-data 6u IPv4 32966 0t0 TCP *:http (LISTEN)
root@redacted:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-11-06 13:24:23 UTC; 16min ago
Docs: man:nginx(8)
Process: 1294 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1295 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1296 (nginx)
Tasks: 3 (limit: 1110)
Memory: 3.1M
CGroup: /system.slice/nginx.service
├─1296 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
├─1297 nginx: worker process
└─1298 nginx: worker process
Nov 06 13:24:23 redacted systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 06 13:24:23 redacted systemd[1]: Started A high performance web server and a reverse proxy server.
root@redacted:~# fuser -v 80/tcp
USER PID ACCESS COMMAND
80/tcp: root 1296 F.... nginx
www-data 1297 F.... nginx
www-data 1298 F.... nginx
Since I didn't touched nginx.conf
, nginx -t
is saying that there is no error. but checking .conf
file fails:
root@redacted:~# nginx -tc /etc/nginx/conf.d/example.com.conf
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/example.com.conf:1
nginx: configuration file /etc/nginx/conf.d/example.com.conf test failed
But I think this isn't relevant of this problem (not sure though).
Even kill all process using port 80 doesn't work neither.
I've searched google for solution of this problem, but haven't found any working one.
PS. I've opened port from iptables
and OC web panel. So port thing won't be the reason of this problem I think.