Hello

Install the NGINX Web Server and Proxy on Oracle Linux

This tutorial provides instructions for installing the NGINX web server and enabling it on Oracle Linux 8 or later.

Background

NGINX is a lightweight HTTP/S server that is capable of higher performance and lower memory use than a typical Apache web server deployment. However, this performance gain comes at the cost of some functionality and flexibility. NGINX has also gained in popularity as a powerful proxy service that is capable of functioning as a direct HTTP proxy, a reverse proxy with caching, an SMTP, POP3 or IMAP proxy or as a generic TCP/UDP proxy. NGINX also provides load balancing services with fault tolerance.

On earlier Oracle Linux versions, the NGINX web server was provided as part of a software collection package. The web server package is now directly available from the Oracle Linux 8 Application Streams repository and therefore simpler to deploy and configure.

What Do You Need?

Install and enable NGINX

Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.

Install the NGINX package

The following command installs the NGINX package and all of its dependencies:

Enable and start the NGINX service

To enable and start the NGINX service for immediate access and make the service start automatically after a reboot, run the following command:

sudo systemctl enable --now nginx.service 

The service starts a web server that listens on TCP port 80 by default. To check the status of the service, run this command:

sudo systemctl status nginx 

Configure firewall rules (Optional)

If you are using a custom firewall profile or an Oracle Cloud Infrastructure instance, open the firewall port for the NGINX web service (80).

These commands enable the firewall port for the NGINX web service and reload the default firewall service:

sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --reload 

Note that in the demonstration environment, the instance has a public facing IP address and no network security is applied. Depending on your production environment, you may need to configure additional security list rules or update your network security group configuration.

Читайте также:  Кластер серверов astra linux

Test your deployment

With your web browser, go to the domain name or IP address of the compute instance. This is the same IP address that you used to SSH into the instance.

The NGINX web server opens the default test page /usr/share/nginx/html/index.html .

Create a custom NGINX configuration

To change the root path for your web server, do not edit the /etc/nginx/nginx.conf file directly. Instead, as a preferred method, create a site-specific configuration in the /etc/nginx/conf.d directory. For example, create the file /etc/nginx/conf.d/default.conf and populate it with a configuration for your site.

The following steps can be used to set up a dedicated site configuration:

    Create a directory to host a new site

cat  EOF | sudo tee /srv/website/index.html    

Hello World!

EOF
sudo chown -R nginx:nginx /srv/website sudo chcon -Rt httpd_sys_content_t /srv/website 
cat EOF | sudo tee /etc/nginx/conf.d/default.conf server < server_name ; root /srv/website; index index.html; > EOF 

Replace the value with the public IP address for the instance.

    Restart the NGINX web service to load the new configuration.

sudo systemctl restart nginx 
sudo tail -f /var/log/nginx/access.log -f /var/log/nginx/error.log 

Configure HTTPS to secure your service

As a best practice, secure all communications between a web browser and your NGINX server by using HTTPS. For a secure setup, a TLS certificate is required.

Configure your TLS/SSL certificates

Oracle strongly recommends using a TLS certificate that has been signed by an external Certificate Authority (CA). See https://docs.oracle.com/en/operating-systems/oracle-linux/certmanage/ for more information.

    For the purpose of this demonstration, you can use a self-signed certificate. To create the certificate and key, run the following command:

openssl req -new -x509 -days 30 -nodes -newkey rsa:2048 -keyout server.key\ -out server.crt -subj "/C=US/ST=Ca/L=Sunnydale/CN=" 
sudo mkdir -p /etc/pki/nginx/private 
sudo cp server.crt /etc/pki/nginx/ sudo cp server.key /etc/pki/nginx/private 

Update the NGINX configuration

  1. Replace the /etc/nginx/conf.d/default.conf file to include a configuration for a TLS enabled web site and include a 301 redirect for HTTP traffic to be referred to the HTTPS site.
cat 'EOF' | sudo tee /etc/nginx/conf.d/default.conf server < server_name ; return 301 https://$host$request_uri; > server < listen 443 ssl http2; listen [::]:443 ssl http2; server_name ; root /srv/website; index index.html; ssl_certificate "/etc/pki/nginx/server.crt"; ssl_certificate_key "/etc/pki/nginx/private/server.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers PROFILE=SYSTEM; ssl_prefer_server_ciphers on; > EOF 
sudo systemctl restart nginx 

Configure the firewall (optional)

Enable the firewall port (443) for the NGINX HTTPS web service and reload the default firewall service.

sudo firewall-cmd --add-service=https --permanent sudo firewall-cmd --reload 

Confirm that HTTPS is working correctly

Open a browser and navigate to http:/// . The browser should redirect to https:/// .

Most browsers display a security risk warning when accessing a site that uses a self-signed certificate. You can accept the risk warning in this case to confirm that the site is working as expected.

The warning is not displayed if you use a CA signed certificate.

Additional Information

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.

Install the NGINX Web Server and Proxy on Oracle Linux

Copyright © 2021, Oracle and/or its affiliates.

Источник

Install the NGINX Web Server and Proxy on Oracle Linux

This tutorial provides instructions for installing the NGINX web server and enabling it on Oracle Linux 8 or later.

Background

NGINX is a lightweight HTTP/S server that is capable of higher performance and lower memory use than a typical Apache web server deployment. However, this performance gain comes at the cost of some functionality and flexibility. NGINX has also gained in popularity as a powerful proxy service that is capable of functioning as a direct HTTP proxy, a reverse proxy with caching, an SMTP, POP3 or IMAP proxy or as a generic TCP/UDP proxy. NGINX also provides load balancing services with fault tolerance.

On earlier Oracle Linux versions, the NGINX web server was provided as part of a software collection package. The web server package is now directly available from the Oracle Linux 8 Application Streams repository and therefore simpler to deploy and configure.

What Do You Need?

Install and enable NGINX

Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.

Install the NGINX package

The following command installs the NGINX package and all of its dependencies:

Enable and start the NGINX service

To enable and start the NGINX service for immediate access and make the service start automatically after a reboot, run the following command:

sudo systemctl enable --now nginx.service 

The service starts a web server that listens on TCP port 80 by default. To check the status of the service, run this command:

sudo systemctl status nginx 

Configure firewall rules (Optional)

If you are using a custom firewall profile or an Oracle Cloud Infrastructure instance, open the firewall port for the NGINX web service (80).

These commands enable the firewall port for the NGINX web service and reload the default firewall service:

sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --reload 

Note that in the demonstration environment, the instance has a public facing IP address and no network security is applied. Depending on your production environment, you may need to configure additional security list rules or update your network security group configuration.

Test your deployment

With your web browser, go to the domain name or IP address of the compute instance. This is the same IP address that you used to SSH into the instance.

The NGINX web server opens the default test page /usr/share/nginx/html/index.html .

Create a custom NGINX configuration

To change the root path for your web server, do not edit the /etc/nginx/nginx.conf file directly. Instead, as a preferred method, create a site-specific configuration in the /etc/nginx/conf.d directory. For example, create the file /etc/nginx/conf.d/default.conf and populate it with a configuration for your site.

The following steps can be used to set up a dedicated site configuration:

    Create a directory to host a new site

cat  EOF | sudo tee /srv/website/index.html    

Hello World!

EOF
sudo chown -R nginx:nginx /srv/website sudo chcon -Rt httpd_sys_content_t /srv/website 
cat EOF | sudo tee /etc/nginx/conf.d/default.conf server < server_name ; root /srv/website; index index.html; > EOF 

Replace the value with the public IP address for the instance.

    Restart the NGINX web service to load the new configuration.

sudo systemctl restart nginx 
sudo tail -f /var/log/nginx/access.log -f /var/log/nginx/error.log 

Configure HTTPS to secure your service

As a best practice, secure all communications between a web browser and your NGINX server by using HTTPS. For a secure setup, a TLS certificate is required.

Configure your TLS/SSL certificates

Oracle strongly recommends using a TLS certificate that has been signed by an external Certificate Authority (CA). See https://docs.oracle.com/en/operating-systems/oracle-linux/certmanage/ for more information.

    For the purpose of this demonstration, you can use a self-signed certificate. To create the certificate and key, run the following command:

openssl req -new -x509 -days 30 -nodes -newkey rsa:2048 -keyout server.key\ -out server.crt -subj "/C=US/ST=Ca/L=Sunnydale/CN=" 
sudo mkdir -p /etc/pki/nginx/private 
sudo cp server.crt /etc/pki/nginx/ sudo cp server.key /etc/pki/nginx/private 

Update the NGINX configuration

  1. Replace the /etc/nginx/conf.d/default.conf file to include a configuration for a TLS enabled web site and include a 301 redirect for HTTP traffic to be referred to the HTTPS site.
cat 'EOF' | sudo tee /etc/nginx/conf.d/default.conf server < server_name ; return 301 https://$host$request_uri; > server < listen 443 ssl http2; listen [::]:443 ssl http2; server_name ; root /srv/website; index index.html; ssl_certificate "/etc/pki/nginx/server.crt"; ssl_certificate_key "/etc/pki/nginx/private/server.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers PROFILE=SYSTEM; ssl_prefer_server_ciphers on; > EOF 
sudo systemctl restart nginx 

Configure the firewall (optional)

Enable the firewall port (443) for the NGINX HTTPS web service and reload the default firewall service.

sudo firewall-cmd --add-service=https --permanent sudo firewall-cmd --reload 

Confirm that HTTPS is working correctly

Open a browser and navigate to http:/// . The browser should redirect to https:/// .

Most browsers display a security risk warning when accessing a site that uses a self-signed certificate. You can accept the risk warning in this case to confirm that the site is working as expected.

The warning is not displayed if you use a CA signed certificate.

Additional Information

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.

Install the NGINX Web Server and Proxy on Oracle Linux

Copyright © 2021, Oracle and/or its affiliates.

Источник

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