0

I am trying to write new line after some match found using Dockerfile but its not working as per my code. I am explaining my code below.

/etc/nginx/conf.d/ubot-nginx.conf::

server {

    listen 90;
    server_name ubot_nginx;

    location / {
        # proxy_pass http://flask_app:5005;
        try_files $uri @app;

        # Do not change this
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location @app {
        include uwsgi_params;
        uwsgi_pass unix:///tmp/uwsgi.sock;
    }

    location /site {
        # rewrite ^/static(.*) /$1 break;
        # root /static;
        alias /app/static/angular;
    }
}

In the above file I need to write some new line i.e-try_files $uri $uri/ /index.html =404; after alias /app/static/angular; so for that I am using below command in my Dockerfile.

RUN sed '/^alias /app/static/angular.*/a try_files $uri $uri/ /index.html =404;' /etc/nginx/conf.d/ubot-nginx.conf

I need here when the image will built the new line given above should be written as per particular match found which is not happening in my case. Please anybody can help me on this ?

Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50
subhra_user
  • 439
  • 5
  • 19
  • if you want in-place file edit with sed use `-i` parameter https://stackoverflow.com/questions/15559359/insert-line-after-match-using-sed – Alexander Ushakov Dec 21 '21 at 06:10
  • I dont want to replace add new line after some match found. – subhra_user Dec 21 '21 at 06:13
  • Not quite sure I understand what you want to end up with, but something like `sed -i -E 's;^(\s*alias /app/static/angular.*);\1\n\ttry_files $uri $uri/ /index.html =404;' /etc/nginx/conf.d/ubot-nginx.conf` ? – Joachim Isaksson Dec 21 '21 at 06:16
  • Your call of sed only send result to standard output and doesn’t change file. If you want to change file (it is called in-place edit) you must use `-i` parameter. – Alexander Ushakov Dec 21 '21 at 06:17
  • @JoachimIsaksson, your suggestion worked but its ignoring `;` after `try_files $uri $uri/ /index.html =404` which caused error in nginx. – subhra_user Dec 21 '21 at 07:46

1 Answers1

1

Try sed -i -E 's|^(\s*alias /app/static/angular.*)|\1\n\ttry_files $uri $uri/ /index.html =404;|' /etc/nginx/conf.d/ubot-nginx.conf

Alexander Ushakov
  • 5,139
  • 3
  • 27
  • 50