欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

How To Install Nginx on Ubuntu 16.04

程序员文章站 2022-07-12 11:19:18
...

原英文链接

本文就简:

Step 1: Install Nginx

首先请保证你的apt源的完整性以及速度

Nginx is available in Ubuntu’s default repositories, so the installation is rather straight forward.(因为Nginx能够在Ubuntu的仓库中找到,所以安装过程就很直接了)

sudo apt-get update
sudo apt-get install nginx

Step 2: Adjust the Firewall

We can list the applications configurations that ufw knows how to work with by typing(键入以下命令就能得到一个应用列表,这个列表中的应用是ufw知道如何自配的)

sudo ufw app list

You should get a listing of the application profiles:

Output

Available applications:
  Nginx Full
  Nginx HTTP
  Nginx HTTPS
  OpenSSH

As you can see, there are three profiles available for Nginx(对于NGINX来说我们有三种模式可供选择)

Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

You can enable this by typing:

sudo ufw allow 'Nginx HTTP'#或者选择Full也行

Step 3: Check your Web Server

e can check with the systemd init system to make sure the service is running by typing:

systemctl status nginx

How To Install Nginx on Ubuntu 16.04

[email protected]:~/.jupyter$ cat /var/www/html/index.html 
<h1>gooooooooooooooooooood!</h1>
[email protected]:~/.jupyter$ curl localhost
<h1>gooooooooooooooooooood!</h1>
[email protected]:~/.jupyter$ 

Step 4: Manage the Nginx Process(管理NGINX程序)

To stop your web server, you can type:

sudo systemctl stop nginx

To start the web server when it is stopped, type:

sudo systemctl start nginx

To stop and then start the service again, type:

sudo systemctl restart nginx

If you are simply making configuration changes, Nginx can often reload without dropping connections. To do this, this command can be used:

sudo systemctl reload nginx

By default, Nginx is configured to start automatically when the server boots. If this is not what you want, you can disable this behavior by typing:

sudo systemctl disable nginx

To re-enable the service to start up at boot, you can type:

sudo systemctl enable nginx

Step 5: Get Familiar with Important Nginx Files and Directories(熟悉NGINX的重要配置文件以及网站目录)

Content(网站内容)

  • /var/www/html: The actual web content, which by default only consists of the default Nginx page you saw earlier, is served out of the /var/www/html directory. This can be changed by altering Nginx configuration files.

Server Configuration(服务器配置)

  • /etc/nginx: The Nginx configuration directory. All of the Nginx configuration files reside here.
  • /etc/nginx/nginx.conf: The main Nginx configuration file. This can be modified to make changes to the Nginx global configuration.
  • /etc/nginx/sites-available/: The directory where per-site “server blocks” can be stored. Nginx will not use the configuration files found in this directory unless they are linked to the sites-enabled directory (see below). Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory.
  • /etc/nginx/sites-enabled/: The directory where enabled per-site “server blocks” are stored. Typically, these are created by linking to configuration files found in the sites-available directory.
  • /etc/nginx/snippets: This directory contains configuration fragments that can be included elsewhere in the Nginx configuration. Potentially repeatable configuration segments are good candidates for refactoring into snippets.

Server Logs(服务器日志)

  • /var/log/nginx/access.log: Every request to your web server is recorded in this log file unless Nginx is configured to do otherwise.
  • /var/log/nginx/error.log: Any Nginx errors will be recorded in this log.