Access to a directory by IP

How to configure nginx to access a directory via IP:
http://xxx.xxx.xxx.xxx/upload

I tried to put this configuration in ngin but I was not successful

server {
listen 80;
server_name 129.213.180.239;
root /home/marcus/web/new.wyddol.com/public_html/launcher;
index index.html index.htm;
}

I put it in the directories:

/etc/nginx/conf.d/nginx.upload.conf
/etc/nginx/conf.d/domains/nginx.upload.conf

But none of these options worked, could anyone help me with this?

Modify the listen directive to use ip:port

server {
listen 129.213.180.239:80;
server_name 129.213.180.239;
root /home/marcus/web/new.wyddol.com/public_html/launcher;
index index.html index.htm;
}

Also, you said you want to use upload directory but in the nginx conf the last directory is launcher, keep that in mind.

Hi @sahsanu ,
Thank you for your quick response. I made the change and now I get this error:
systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2024-03-31 13:04:26 UTC; 20s ago
Process: 199895 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

Starting nginx - high performance web server…
nginx[199895]: nginx: [emerg] bind() to 129.213.180.239:80 failed (99: Cannot assign requested address)
systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
systemd[1]: nginx.service: Failed with result ‘exit-code’.
systemd[1]: Failed to start nginx - high performance web server.
Connection to 129.213.180.239 closed by remote host.

I also verified that in the
/home/wyddol/conf/web/new.wyddol.com/nginx.conf
The listen is like this:
listen 10.0.0.97:80;

I changed it to this IP and now I get a:
404 Not Found

Of course, if your server doesn’t have assigned the public ip, nginx can’t listen on that ip.

So, are you using this conf and you receive a 404 code?

server {
listen 10.0.0.97:80;
server_name 129.213.180.239;
root /home/marcus/web/new.wyddol.com/public_html/launcher;
index index.html index.htm;
}

How are you trying to test it? What is the url you are using to test it? Is there an index.html or index.htm file inside /home/marcus/web/new.wyddol.com/public_html/launcher/?

That’s right @sahsanu , inside the directory there is an index.html

http://129.213.180.239/launcher/index.html

If you are using that route you should use this conf:

server {
listen 10.0.0.97:80;
server_name 129.213.180.239;
root /home/marcus/web/new.wyddol.com/public_html;
index index.html index.htm;
}

It looks like this now:

But the Not Found nginx error follows

Did you restart nginx? If you did then check the nginx logs or better, use a domain/subdomain instead of the ip. You can even use one of these domains if you don’t want to add your own domain to that ip:

129.213.182.239.nip.io
129-213-182-239.nip.io
129.213.182.239.sslip.io
129-213-182-239.sslip.io

nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2024-03-31 13:23:31 UTC; 3h 42min ago
Process: 4023 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 4024 (nginx)
Tasks: 4 (limit: 14189)
Memory: 6.7M
CGroup: /system.slice/nginx.service
├─4024 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─4025 nginx: worker process
├─4026 nginx: worker process
└─4027 nginx: cache manager process

Mar 31 13:23:31 panel.wyddol.com systemd[1]: Starting nginx - high performance web server…
Mar 31 13:23:31 panel.wyddol.com systemd[1]: Started nginx - high performance web server.

So, the domain works correctly, the problem is that I have an application that can only access through the domain, if it is through the domain URL it gives an error

systemctl restart nginx

I’m sorry for the error and thank you very much for your patience, I now ran the correct command again:

But the 404 not found error follows for this configuration:

Come on, I changed the configuration to:

server {
        listen 129.213.180.239:80;
        server_name 129.213.180.239;
        root /home/marcus/web/new.wyddol.com/public_html;
        index index.html index.htm;
}

Now returns this:

systemctl restart nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root@panel:/etc/nginx/conf.d/domains# journalctl -xe

Running the journalctl -x command I get this:

journalctl -xe
-- 
-- The job identifier is 2036.
Mar 31 17:35:38 wyddol nginx[22264]: nginx: [emerg] bind() to 129.213.180.239:80 failed (99: Cannot assign requested address)
Mar 31 17:35:38 wyddol systemd[1]: wyddol: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- 
-- An ExecStart= process belonging to unit nginx service has exited.
-- 
-- The process' exit code is 'exited' and its exit status is 1.
Mar 31 17:35:38 wyddol systemd[1]: nginx service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- 
-- The unit nginx service has entered the 'failed' state with result 'exit-code'.
Mar 31 17:35:38 wyddol systemd[1]: Failed to start nginx - high performance web server.
-- Subject: A start job for unit nginx service has failed
-- Defined-By: systemd
-- 
-- A start job for unit nginx service has finished with a failure.
-- 
-- The job identifier is 2036 and the job result is failed.
Mar 31 17:35:43 wyddol sshd[22265]: Invalid user ubnt from 212.70.149.150 port 62840
Mar 31 17:35:44 wyddol sshd[22265]: Received disconnect from 212.70.149.150 port 62840:11: Bye [preauth]
Mar 31 17:35:44 wyddol sshd[22265]: Disconnected from invalid user ubnt 212.70.149.150 port 62840 [preauth]
Mar 31 17:35:54 wyddol sudo[22271]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 31 17:35:54 wyddol sudo[22271]: pam_unix(sudo:session): session closed for user root
Mar 31 17:35:54 wyddol sudo[22284]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 31 17:35:54 wyddol sudo[22284]: pam_unix(sudo:session): session closed for user root
Mar 31 17:35:54 wyddol sudo[22315]: pam_unix(sudo:session): session opened for user root by (uid=0)
Mar 31 17:35:54 wyddol sudo[22315]: pam_unix(sudo:session): session closed for user root
Mar 31 17:36:01 wyddol CRON[22333]: pam_unix(cron:session): session opened for user admin b

Apparently I have permission problems.

I will redo the settings, thank you for your patience and attention.
Thanks @sahsanu

It is not a perms problem, you can’t use the public ip in listen directive if your server does’have that ip assigned.

I tested it in my own server and it works but my server has its own public ip directly assigned. Sorry but I can’t test it in a server with a private address assigned and a nated public ip :frowning:

Hmmm, I understand, I’m really using a Private IP in an Attached VNICs, that’s probably it, correct?