No package nginx available error nothing to do

Welcome back for another tutorial! This time I'm going to show you how to get started with NGINX on CentOS 7.CentOS 7 has been out for quite a while now, but it's not become a standard quite yet. Since they made some big changes to the way CentOS works, migrations aren't exactly what you'd call easy. In the end, though,

 lowendtutorial

Welcome back for another tutorial! This time I’m going to show you how to get started with NGINX on CentOS 7.

CentOS 7 has been out for quite a while now, but it’s not become a standard quite yet. Since they made some big changes to the way CentOS works, migrations aren’t exactly what you’d call easy. In the end, though, CentOS 7 will be used by more and more people. Including those willing to run a web server!

NGINX is a popular option these days for a web server, mostly because it’s able to handle a very high number of concurrent requests. A popular set up is to use it as a proxy for Apache, which can then serve application requests. That will not be covered in this tutorial, though.

So, let’s set up NGINX on CentOS 7. I’m expecting a clean install here!

This tutorial has been updated on October 3rd.

Preparing your environment

First let’s start by ensuring your system is up-to-date. This will not only update any packages that may have an update pending, but will also update the repository caches ensuring that any packages added meanwhile have been added:

sudo yum update

When is asks you to continue, please type ‘y’ to ensure everything gets updated properly.

Now, where in former CentOS versions you often had to add a separate repository to get any kind of decent version of NGINX (or NGINX at all), with CentOS 7 it’s just in the main repositories.

On most servers, nginx is not available immediately without performing some additional steps. If, however, you are using an OpenVZ server and are lucky enough to have installed it with a template with the proper repository added, you are ready to go. There’s a simple check to perform to see if you need an additional repository. Run:

sudo yum install nginx

If this returns the following:

No package nginx available.

Then you need to follow these additional steps. If not, continue to the part ‘Installation’.

CentOS doesn’t ship with NGINX in its repositories by default. Therefore we need to add a different repository, called the ‘EPEL’ repository. This repository contains a lot of packages, amongst which NGINX. To add it, run:

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

You are now set to install nginx!

Installation

Installation is easy:

sudo yum install nginx

It again asks you if you want to continue. Several other packages have been selected as well, as NGINX requires those. Type ‘y’ again to start the installation.

Once the installation is finished, NGINX will have been installed but is not yet running. In order to start it, type:

sudo systemctl start nginx

You should now be able to go to you server’s IP address and you should see NGINX’s default page. That’s how easy it was!

Two more things, though:

First of all, if you reboot, NGINX won’t be started automatically. In order to achieve that, run the following command:

sudo systemctl enable nginx

The command itself doesn’t start NGINX, but ensures it starts automatically at boot. And it would be quite convenient if that were the case, of course.

Second, the default page may not be what you are looking for. So, if you want to replace the default files with something else, go to the following directory:

/usr/share/nginx/html

And modify/replace the files in there. Either do this as root (‘sudo su root’) or use sudo before every command to ensure things go well. Alternatively, you can make all the files owned by www-data, by running:

sudo chown -R www-data:www-data /usr/share/nginx/html


That’s it for this time! Hope you liked the tutorial!

Related Posts:

  • Author
  • Recent Posts

Maarten Kossen was the administrator of LowEndBox from 2013 to 2015, and brought many ideas and improvements to the website during his leadership. Today he is member of our community and LowEndTalk.

Продолжаю серию статей, а это уже вторая, об установке сервисов на ОС Linux.
Сегодня речь пойдет о простой установке веб сервера nginx и последней версии PHP, за 5 минут.

Быстрая установка вебсервера nginx

Речь опять идет о сервере с установленной операционной системой из серии CentOS/Fedora/RHEL/Oracle Linux.

Для начала мы установим PHP, на момент написания статьи — это версия 5.4.7:

1) Добавляем репозиторий Webtatic с последними версиями PHP, выполняем команду в зависимости от версии Вашей ОС:

Для CentOS 6/RHEL 6/Oracle Linux 6 :

rpm -Uvh http://repo.webtatic.com/yum/el6/latest.rpm

Для более старой версии CentOS 5/RHEL 5/Oracle Linux 5:

rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm

2) Устанавливаем основные модули PHP:

yum -y install php54w php54w-mbstring php54w-fpm php54w-mysql php54w-gd php54w-pear php54w-pdo

3) Устанавливаем репозиторий с последними версиями Nginx:

Для этого создаем файл:

vi /etc/yum.repos.d/nginx.repo

И записываем туда информацию в зависимости от версии Вашей ОС:

Для CentOS/Oracle Linux:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

Для RHEL:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1

4) Теперь просто устанавливаем последнюю версию Nginx:

yum -y install nginx

5) Запускаем сервер обработки PHP (php-fpm):

Перед запуском необходимо немного поправить конфигурацию:

vi /etc/php-fpm.d/www.conf

И заменить строчки:

user = apache
group = apache

На:

user = nginx
group = nginx

Запускаем наш сервер PHP-FPM:

service php-fpm start

6) Теперь добавляем наш сайт (в примере это будет nash-site.ru) в конфигурацию нашего веб сервера Nginx:

vi /etc/nginx/conf.d/nash-site.conf

И вставляем туда такие строки:

server {
listen 80;
server_name nash-site.ru;
access_log /var/log/nginx/log/nash-site.ru.access.log main;
location / {
root /usr/share/nginx/nash-site.ru;
index index.php index.html index.htm;
}
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;
}

location ~ /.ht {
deny all;
}
}

7) Создаем папку для нашего сайта:

mkdir /usr/share/nginx/nash-site.ru
chown nginx:nginx /usr/share/nginx/nash-site.r

И можно заливать туда наш сайт.

8) Старт веб сервера и добавление сервисов в автозагрузку:

service nginx start
chkconfig php-fpm on
chkconfig nginx on

Yongchang He

Yongchang He

Posted on Jan 21, 2022

• Updated on Feb 8, 2022

This demo is based on: Amazon Linux 2 AMI (AWS EC2)

The first step is to turn yourself as Root user and upgrade your EC2 instance:

sudo su
yum upgrade 

Enter fullscreen mode

Exit fullscreen mode

The two most popular program to run web server are Apache and Nginx. In this tutorial I will use Nginx to show the steps.

I masked my IP address as ADDRESS for security reasons.

[root@ip-ADDRESS ec2-user]# yum install nginx
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
No package nginx available.
Error: Nothing to do
nginx is available in Amazon Linux Extra topic "nginx1"

To use, run
# sudo amazon-linux-extras install nginx1

Learn more at
https://aws.amazon.com/amazon-linux-2/faqs/#Amazon_Linux_Extras

Enter fullscreen mode

Exit fullscreen mode

Then run the command as Amazon recommended:

[root@ip-ADDRESS ec2-user]# sudo amazon-linux-extras install nginx1

Enter fullscreen mode

Exit fullscreen mode

If the installation is completed successfully, the next step is to run the Nginx.

But before running the Nginx, let’s try read the initial web content of Nginx using curl command:

[root@ip-ADDRESS ec2-user]#curl localhost:80

Enter fullscreen mode

Exit fullscreen mode

When the Nginx service is stopped, you will get the following message:

[root@ip-ADDRESS ec2-user]#  curl localhost:80
curl: (7) Failed to connect to localhost port 80 after 0 ms: Connection refused

Enter fullscreen mode

Exit fullscreen mode

So, let’s start the Nginx service:

[root@ip-ADDRESS ec2-user]# service nginx start
Redirecting to /bin/systemctl start nginx.service

Enter fullscreen mode

Exit fullscreen mode

And then, type the following command:

[root@ip-ADDRESS ec2-user]# curl localhost:80

Enter fullscreen mode

Exit fullscreen mode

You will get:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Test Page for the Nginx HTTP Server on Amazon Linux</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style type="text/css">
            /*<![CDATA[*/
            body {
                background-color: #fff;
                color: #000;
                font-size: 0.9em;
                font-family: sans-serif,helvetica;
                margin: 0;
                padding: 0;
            }
            :link {
                color: #c00;
            }
            :visited {
                color: #c00;
            }
            a:hover {
                color: #f50;
            }
            h1 {
                text-align: center;
                margin: 0;
                padding: 0.6em 2em 0.4em;
                background-color: #294172;
                color: #fff;
                font-weight: normal;
                font-size: 1.75em;
                border-bottom: 2px solid #000;
            }
            h1 strong {
                font-weight: bold;
                font-size: 1.5em;
            }
            h2 {
                text-align: center;
                background-color: #3C6EB4;
                font-size: 1.1em;
                font-weight: bold;
                color: #fff;
                margin: 0;
                padding: 0.5em;
                border-bottom: 2px solid #294172;
            }
            hr {
                display: none;
            }
            .content {
                padding: 1em 5em;
            }
            .alert {
                border: 2px solid #000;
            }

            img {
                border: 2px solid #fff;
                padding: 2px;
                margin: 2px;
            }
            a:hover img {
                border: 2px solid #294172;
            }
            .logos {
                margin: 1em;
                text-align: center;
            }
            /*]]>*/
        </style>
    </head>

    <body>
        <h1>Welcome to <strong>nginx</strong> on Amazon Linux!</h1>

        <div class="content">
            <p>This page is used to test the proper operation of the
            <strong>nginx</strong> HTTP server after it has been
            installed. If you can read this page, it means that the
            web server installed at this site is working
            properly.</p>

            <div class="alert">
                <h2>Website Administrator</h2>
                <div class="content">
                    <p>This is the default <tt>index.html</tt> page that
                    is distributed with <strong>nginx</strong> on
                     Amazon Linux.  It is located in
                    <tt>/usr/share/nginx/html</tt>.</p>

                    <p>You should now put your content in a location of
                    your choice and edit the <tt>root</tt> configuration
                    directive in the <strong>nginx</strong>
                    configuration file
                    <tt>/etc/nginx/nginx.conf</tt>.</p>

                </div>
            </div>

            <div class="logos">
                <a href="http://nginx.net/"><img
                    src="nginx-logo.png" 
                    alt="[ Powered by nginx ]"
                    width="121" height="32" /></a>
            </div>
        </div>
    </body>
</html>

Enter fullscreen mode

Exit fullscreen mode

If you fail to start Nginx service, it might be that the hosting provider preinstalled Apache on your instance by default during a fresh install. Just run the following commands:

sudo fuser -k 80/tcp
sudo fuser -k 443/tcp

Enter fullscreen mode

Exit fullscreen mode

Then it might be OK to restart it:

sudo service nginx restart

Enter fullscreen mode

Exit fullscreen mode

By now, if you paste your public ip address in your browser, you still cannot see the index Nginx webpage. This is because you haven’t open the 80 port in your AWS Security Group.

Now edit inbound rules, and add 80 port to your security groups.

The last step, to refresh your web browser again which you typed your public ip address of your EC2 instance, and you will get the welcome page of Nginx.

Welcome to Nginx on Amazon Linux.

Понравилась статья? Поделить с друзьями:
  • No overload matches this call the last overload gave the following error
  • No operating system found boot sequence will automatically repeat lenovo как исправить
  • No ole db error information found hr 0x80004005
  • No nzxt devices were found как исправить
  • No nearby devices were found как исправить на телефоне самсунг