cancel

在 EB-336x 主机上使用 Linux Debian 9操作系统中安装和设置 Nginx 服务器

2021-12-01

Nginx 是一个开源 HTTP/HTTPS web 服务器,也可以用作代理服务器。与反向代理服务器的 HTTP、HTTPS 和其他协议兼容,您现在可以使用 Nginx 代替传统的 Apache HTTP2 服务器。

eb336xWeb_img6

本节介绍如何使用 Linux Debian 9在 EB-3362 上安装和设置 Nginx web 服务器

准备

  • EB-3362
  • SD 卡(内置 Debian 9)
  • 屏幕监视器
  • 键盘
  • 以太网
eb336xWeb_img1
eb336xWeb_img2

安装 Nginx 服务器

Step 1: 安装 Nginx 服务器

  • 输入以下apt-get command/apt command 以更新系统:
    $ sudo apt update
    $ sudo apt upgrade
  • 要安装 Nginx 服务器,请输入:
    $ sudo apt install nginx
  • 默认情况下,启动的 Nginx 服务器将在 Debian 9 上启动,可以使用 netstat command/ss command 和 ps command 进行验证,如下所示:
    $ ps aux | grep nginx
    $ pgrep nginx
  • 使用如下 netstat command 验证端口80是否打开:
    $ netstat -tulpn | grep :80
eb336xWeb_img3

Step 2: 测试 Nginx 服务器

  • 打开 web 浏览器并键入 url:
    http://your-domain/
  • 或使用 ip command/ifconfig command查找您的公共 IP 地址:
    $ ip a
  • OR
    $ ifconfig eth0
eb336xWeb_img4

Step 3: 配置 Nginx 服务器

在 Nginx 中,所有 HTML、CSS 和图像文件默认存储在/var/www/HTML 目录中,称为 web 服务器的根目录。
默认目录可以在/etc/nginx/sites-enabled/default 配置文件中修改。您可以使用vim commandnano command对其进行编辑。

  • 键入以下 vim command/nano command 以设置 web 服务器默认文件。
    $ sudo vi /etc/nginx/sites-enabled/default
    OR
    $ sudo nano /etc/nginx/sites-enabled/default
    /etc/nginx/sites.conf 是您的主要 nginx 配置文件,而 /etc/nginx/sites-enabled/default 是默认配置文件。
  • 要创建名为“icopdemo”的虚拟主机,请輸入:
    $ sudo nano /etc/nginx/sites-available/icopdemo
  • 并在“icopdemo”中输入以下代码:
    server {
        listen 80;
        listen [::]:80;
     
        server_name icopdemo;
     
        root /home/icop/www;
        index index.html;
     
        location / {
            try_files $uri $uri/ =404;
        }
    }
  • 让文件与“icopdemo”同步,并删除默认文件。
    • 同步:
      $ sudo ln -s /etc/nginx/sites-available/icopdemo /etc/nginx/sites-enabled/
    • 删除默认文件:
      $ sudo rm /etc/nginx/sites-enabled/default
  • 建立网页位置的路径并创建网页。
    $ sudo mkdir ~/www
    $ sudo nano ~/www/index.html
  • 在索引中输入以下网站代码.html:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to Icop Tech</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to ICOP Tech</h1>
    <p>This is a test for Nginx web server.</p>
     
    <p><em>Hello world.</em></p>
    </body>
    </html>
  • 保存并关闭文件。
    重新加载 Nginx 服务器以启动新的 web 服务器。
    $ sudo systemctl reload nginx
eb336xWeb_img5

输入 IP 址以显示来自 Nginx web 服务器的网页(~/www/index.html)。
您可以替换~/www/index。包含要显示的网页的 html。


Main features of EB-3362-L2C2851G1E-I:

  • DM&P SoC Vortex86DX3- 1GHz
  • 1GB / 2GB DDR3 onboard
  • 3S / 3U / VGA / GLAN / LAN / Audio / 8GPIO / SATA / 8~24V
  • Operation Temperature: -20 ~ +70°C
  • Auto Power On
  • VESA Mount

欲了解更多信息和样品请求,请写信至 info@icop.com.tw,请致电最近的 ICOP 分公司或联系我们的全球官方经销商。

Δ