Why am I unable to run Nginx on any port other than the default 80, when I am specifically mentioning in the YAML file that i want it to run on port 1234 (and not on 80)?
nginx gets its default port out of a config file, found in /etc/nginx. The default nginx container actually loads the file /etc/nginx/conf.d/default.conf, which looks like this:
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
This is what’s preventing you from using a different port. The solution is to mount a different configuration into the container that the container will load, say, at /etc/nginx/conf.d/default.conf. This will allow you to change the port the program uses.
To serve static files, you can do something similar by mounting an html directory at /usr/share/nginx/html (unless you change that in the config, which you now see you can do).
Oh i didn’t know this, thanks Rob. Is this only specific to nginx? If i run a flask/fastapi ML app with uvicorn serving it, will uvicorn also run on default 80 and will ignore the port we specify in YAML file (say 1234) and same with streamlit , as in streamlit will always run on port 5000 unless we do the changes to the config file for uvicorn and streamlit?
I think that python http servers like uvicorn (sp?) get their port from the command line that launches them, so you can set the port by using command and args. Some web servers look for an environment variable. But nginx is a legacy web server that was popular before
Docker Ruled The World
so it uses its original config file scheme; I’d guess that apache httpd does something similar, since it’s even more venerable than nginx.
