Как я могу найти и отредактировать несколько строк и заменить их, используя sed в nginx / sites-available / default

Мне нужно раскомментировать существующий текст в файле по умолчанию

файл на этом сайте очень похож на мой файл по умолчанию

https://salsa.debian.org / nginx-team / nginx / blob / master / debian / conf / sites-available / default

отличие состоит в том, что, поскольку я использую сертификат https, у меня есть файл по умолчанию, другой раздел сервера {} и внутри него у меня есть еще одно вхождение этой следующей части ... поэтому мне нужно найти в первом разделе server {} и добавить info.php в строку со стрелкой, которую я создал для демонстрации, в какой строке я хочу добавить info.php

сервер {

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

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
            #include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
            #fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
            #fastcgi_pass 127.0.0.1:9000;
            #include fastcgi_params;
    #}

    # 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 someport;
    #       listen [::]:someport;
    #
    #       server_name example.com;
    #
    #       root /var/www/example.com;
    #       index index.html;
    #
    #       location / {
    #               try_files $uri $uri/ =404;
    #       }
    #}

}

, а затем выполнить поиск в следующем разделе сервера {}, и в этой части мне нужно изменить это:

сервер {

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;
    server_name mydomainname.com; # managed by Certbot

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

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
            #include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
            #fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
            #fastcgi_pass 127.0.0.1:9000;
            #include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
            #deny all;
    #}
    listen [::]:someport ssl ipv6only=on; # managed by Certbot
    listen someport ssl; # managed by Certbot

}

по адресу:

сервер {

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;
    server_name mydomainname.com; # managed by Certbot

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

    }
    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
            #fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny all;
    }
    listen [::]:someport ssl ipv6only=on; # managed by Certbot
    listen someport ssl; # managed by Certbot

}

I я уже пробовал sed, но я не очень хорош в его синтаксисе, потому что я получаю всевозможные ошибки о специальных символах в нем, может кто-нибудь помочь мне с этим один?

0
задан 8 July 2019 в 17:34

1 ответ

Действительно, Вы не можете...

sed может соответствовать шаблонам и отредактировать Ваши данные из этого, но они действительно не видят различия между строками комментария и командными строками.

Так как это - такой маленький файл, намного легче открыть его в некотором редакторе и сделать, редактирование вручную - использует vi, нано, gedit или независимо от того, что Ваш фаворит.

0
ответ дан 24 October 2019 в 00:40

Другие вопросы по тегам:

Похожие вопросы: