Hello, Nginx!

Install¶

Most Linux distributions and BSD variants have NGINX in the usual package repositories and they can be installed via whatever method is normally used to install software ( apt on Debian, emerge on Gentoo, ports on FreeBSD, etc).

Be aware that these packages are often somewhat out-of-date. If you want the latest features and bugfixes, it’s recommended to build from source or use packages directly from nginx.org.

Official Red Hat/CentOS packages¶

To add NGINX yum repository, create a file named /etc/yum.repos.d/nginx.repo and paste one of the configurations below:

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

Due to differences between how CentOS, RHEL, and Scientific Linux populate the $releasever variable, it is necessary to manually replace $releasever with either 5 (for 5.x) or 6 (for 6.x), depending upon your OS version.

Official Debian/Ubuntu packages¶

The available NGINX Ubuntu release support is listed at this distribution page. For a mapping of Ubuntu versions to release names, please visit the Official Ubuntu Releases page.

Append the appropriate stanza to /etc/apt/sources.list . If there is concern about persistence of repository additions (i.e. DigitalOcean Droplets), the appropriate stanza may instead be added to a different list file under /etc/apt/sources.list.d/ , such as /etc/apt/sources.list.d/nginx.list .

## Replace $release with your corresponding Ubuntu release. deb https://nginx.org/packages/ubuntu/ $release nginx deb-src https://nginx.org/packages/ubuntu/ $release nginx

e.g. Ubuntu 20.04 (Focal Fossa):

deb https://nginx.org/packages/ubuntu/ focal nginx deb-src https://nginx.org/packages/ubuntu/ focal nginx

To install the packages, execute in your shell:

sudo apt update sudo apt install nginx

If a W: GPG error: https://nginx.org/packages/ubuntu focal InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY $key is encountered during the NGINX repository update, execute the following:

## Replace $key with the corresponding $key from your GPG error. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key sudo apt update sudo apt install nginx

You have now nginx installed on your server but not ready to serve web pages. you have to start the nginx. You can do this by using this command:

sudo systemctl start nginx

Append the appropriate stanza to /etc/apt/sources.list .

deb https://nginx.org/packages/debian/ squeeze nginx deb-src https://nginx.org/packages/debian/ squeeze nginx

Ubuntu PPA¶

This PPA is maintained by volunteers and is not distributed by nginx.org. It has some additional compiled-in modules and may be more fitting for your environment.

Читайте также:  Http load test linux

You can get the latest stable version of NGINX from the NGINX PPA on Launchpad: You will need to have root privileges to perform the following commands.

For Ubuntu 20.04 and newer:

sudo -s nginx=stable # use nginx=development for latest development version add-apt-repository ppa:nginx/$nginx apt update apt install nginx

If you get an error about add-apt-repository not existing, you will want to install python-software-properties . For other Debian/Ubuntu based distributions, you can try the lucid variant of the PPA which is the most likely to work on older package sets:

sudo -s nginx=stable # use nginx=development for latest development version echo "deb http://ppa.launchpad.net/nginx/$nginx/ubuntu lucid main" > /etc/apt/sources.list.d/nginx-$nginx-lucid.list apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C apt update apt install nginx

Official Win32 Binaries¶

As of NGINX 0.8.50, NGINX is now available as an official Windows binary.

cd c:\ unzip nginx-1.2.3.zip ren nginx-1.2.3 nginx cd nginx start nginx
nginx -s [ stop | quit | reopen | reload ] 

For problems look in c:nginxlogserror.log or in EventLog.

In addition, Kevin Worthington maintains earlier Windows builds of the development branch.

Source Releases¶

There are currently two versions of NGINX available: stable (1.20.x) , mainline (1.21.x) . The mainline branch gets new features and bugfixes sooner but might introduce new bugs as well. Critical bugfixes are backported to the stable branch.

In general, the stable release is recommended, but the mainline release is typically quite stable as well. See the FAQ .

Источник

Install and configure Nginx

Nginx (pronounced as “Engine-X”) is an open source web server that is often used as reverse proxy or HTTP cache. It is available for Linux for free.

Читайте также:  Установка zabbix server astra linux

In this tutorial we’ll install Nginx and set up a basic site.

What you’ll learn

What you’ll need

Originally authored by Marcin Mikołajczak

2. Installing Nginx

To install Nginx, use following command:

sudo apt update sudo apt install nginx 

After installing it, you already have everything you need.

You can point your browser to your server IP address. You should see this page:

Welcome to nginx

If you see this page, you have successfully installed Nginx on your web server.

3. Creating our own website

Default page is placed in /var/www/html/ location. You can place your static pages here, or use virtual host and place it other location.

Virtual host is a method of hosting multiple domain names on the same server.

Let’s create simple HTML page in /var/www/tutorial/ (it can be anything you want). Create index.html file in this location.

cd /var/www sudo mkdir tutorial cd tutorial sudo "$" index.html 

Paste the following to the index.html file:

      

Hello, Nginx!

We have just configured our Nginx web server on Ubuntu Server!

Save this file. In next step we are going to set up virtual host to make Nginx use pages from this location.

4. Setting up virtual host

To set up virtual host, we need to create file in /etc/nginx/sites-enabled/ directory.

For this tutorial, we will make our site available on 81 port, not the standard 80 port. You can change it if you would like to.

cd /etc/nginx/sites-enabled sudo "$" tutorial 

root is a directory where we have placed our .html file. index is used to specify file available when visiting root directory of site. server_name can be anything you want, because you aren’t pointing it to any real domain by now.

Читайте также:  Arch linux gnome настройка

5. Activating virtual host and testing results

To make our site working, simply restart Nginx service.

sudo service nginx restart 

Let’s check if everything works as it should. Open our newly created site in web browser. Remember that we used :81 port.

Final

Congratulations! Everything works as it should. We have just configured Nginx web server.

6. That’s all!

I hope that this tutorial explained you the basics of working with Nginx. Of course, it’s much more powerful tool. You can find more in official resources, available on Nginx site.

If you need more guidance on using Nginx, help is always at hand:

Further reading:

Источник

Оцените статью
Adblock
detector