Home > front end >  How to do make changes in default file of nginx deployed on Pod
How to do make changes in default file of nginx deployed on Pod

Time:12-03

I have default nginx file which I am copying on /etc/nginx/sites-available/ location, when I do certain changes in default file the changes are not getting reflected in that file under pod.

I have mentioned the copy command to copy default file under /etc/nginx/sites-available/, wanted to know if this default file is being auto generated by nginx as a result not able to reflect my changes. Is there any way to change default file?

I tried by directly changing the default file inside pod but once pod gets restart changes will be lost.

default file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        #Sample testing to the file
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:8000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    #
        # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

Dockerfile

FROM node:12.10.0

ENV APP_ROOT /usr/src/webapp/
ENV DOC_ROOT /var/www/html/

ENV DEV_ENV development
ENV DEV_BASE_HREF https://app.com/app-development/

RUN mkdir -p $APP_ROOT $DOC_ROOT
RUN chmod 777 $DOC_ROOT

COPY . $APP_ROOT

RUN chmod 777 init.sh

RUN apt-get update \
    && apt-get install nginx -y

RUN npm cache clean --force \
    && npm rebuild node-sass \
    && npm install -g @angular/[email protected] --unsafe

RUN rm -rf /etc/nginx/sites-available/default

COPY default /etc/nginx/sites-available/default

RUN ls /etc/nginx/sites-available && cat /etc/nginx/sites-available/default



RUN npm cache clear --force && npm install --no-shrinkwrap --update-binary


RUN node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod --env=prod -extract-css false --base-href $DEV_BASE_HREF --output-path=./dist 

EXPOSE 80
ENTRYPOINT ["/bin/bash", "init.sh"]
CMD ["dev"]

CodePudding user response:

Not sure why you are using the Nginx and Node both in single Dockerfile

ideally, you should be running the single process inside the container.

COPY ./nginx/default.conf /etc/nginx/nginx.conf 

You can overwrite the file inside the Dockerfile like above.

COPY default /etc/nginx/sites-available/default

Make sure your file is getting removed or else you can run the remove command

RUN ls /etc/nginx/sites-available && cat /etc/nginx/sites-available/default

verify actually your file getting placed into docker

RUN npm cache clean --force \
    && npm rebuild node-sass \
    && npm install -g @angular/[email protected] --unsafe

RUN rm /etc/nginx/sites-available/default

COPY default /etc/nginx/sites-available/

RUN ls /etc/nginx/sites-available && cat /etc/nginx/sites-available/default


RUN npm cache clear --force && npm install --no-shrinkwrap --update-binary
  • Related