如何在 Ubuntu 20.04 上使用 Nginx 安装 OSClass如何在 Ubuntu 20.04 上使用 Nginx 安装 OSClass如何在 Ubuntu 20.04 上使用 Nginx 安装 OSClass如何在 Ubuntu 20.04 上使用 Nginx 安装 OSClass
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

如何在 Ubuntu 20.04 上使用 Nginx 安装 OSClass

发表 admin at 2025年2月28日
类别
  • 未分类
标签

本教程适用于这些操作系统版本

  • Ubuntu 20.04(Focal Fossa)
  • Ubuntu 18.04(仿生海狸)

在此页

  1. 先决条件
  2. 安装 LEMP 堆栈
  3. 为 Osclass 创建数据库
  4. 下载 Osclass
  5. 为 Osclass 配置 Nginx
  6. 使用 Lets Encrypt 保护 Osclass
  7. 访问 Osclass
  8. 结论

Osclass 是一款免费、开源且用户友好的应用程序,可用于在您自己的服务器上创建您自己的分类网站。它带有功能丰富的编辑器、用户友好的管理门户、灵活的模板系统,可帮助您在没有任何技术知识的情况下创建自己的列表站点。它具有一系列功能,包括多语言、验证码、仪表板、SEO 友好、集成搜索引擎、免费网站创建者等等。

在本教程中,我们将介绍如何在 Ubuntu 20.04 服务器上使用 Nginx 和 Lets Encrypt SSL 安装 Osclass 分类网站 cms。

先决条件

  • 一台运行 Ubuntu 20.04 的服务器。
  • 用您的服务器 IP 指向的有效域名。
  • 为服务器配置了根密码。

安装 LEMP 堆栈

首先,您需要在服务器中安装 Nginx Web 服务器、MariaDB 服务器、PHP 和其他所需的包。您可以使用以下命令安装所有这些:

apt-get install nginx mariadb-server php7.4 php7.4-cli php7.4-fpm php7.4-common php7.4-mysql php7.4-gd php7.4-xml curl gnupg2 unzip -y

安装所有软件包后,您可以继续下一步。

为 Osclass 创建数据库

接下来,您需要为 Osclass 创建数据库和用户。首先,使用以下命令登录 MariaDB:

mysql

登录后,使用以下命令为 Osclass 创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE osclass;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON osclass.* TO 'osclass'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令刷新权限并退出 MariaDB shell:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

完成后,您可以继续下一步。

下载 Osclass

首先,您需要从 Git 存储库下载最新版本的 Osclass。您可以使用以下命令下载它:

wget https://github.com/Dis555/Osclass/releases/download/4.2.0/Osclass-Evolution4.2.0.zip

下载完成后,使用以下命令将下载的文件解压缩到 Nginx 根目录:

unzip Osclass-Evolution4.2.0.zip -d /var/www/html/osclass

接下来,将 osclass 目录的所有权更改为 www-data 并使用以下命令授予适当的权限:

chown -R www-data:www-data /var/www/html/osclass
chmod -R 755 /var/www/html/osclass

完成后,您可以继续下一步。

为 Osclass 配置 Nginx

接下来,您需要创建一个 Nginx 虚拟主机配置文件来为 Osclass 服务。您可以使用以下命令创建它:

nano /etc/nginx/sites-available/osclass.conf

添加以下行:

server {
    listen 80;
    listen [::]:80;

    server_name osclass.linuxbuz.com;
    root /var/www/html/osclass;

    index index.php index.html;

    location / {
      try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Check this
    }
}

保存并关闭文件,然后使用以下命令启用 Nginx 虚拟主机:

ln -s /etc/nginx/sites-available/osclass.conf /etc/nginx/sites-enabled/

接下来,使用以下命令检查 Nginx 是否存在任何配置错误:

nginx -t

您应该得到以下输出:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

最后,重新启动 Nginx 服务以应用更改:

systemctl restart nginx

接下来,使用以下命令验证 Nginx 服务的状态:

systemctl status nginx

您应该看到以下输出:

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-08-13 06:21:23 UTC; 4s ago
       Docs: man:nginx(8)
    Process: 13399 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 13412 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 13415 (nginx)
      Tasks: 3 (limit: 2353)
     Memory: 3.5M
     CGroup: /system.slice/nginx.service
             ??13415 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??13416 nginx: worker process
             ??13417 nginx: worker process

Aug 13 06:21:23 ubunt4 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 13 06:21:23 ubunt4 systemd[1]: Started A high performance web server and a reverse proxy server.

完成后,您可以继续下一步。

使用 Lets Encrypt 保护 Osclass

使用 Lets Encrypt SSL 保护您的 Osclass 网站始终是个好主意。首先,您需要在服务器中安装 Certbot 客户端。 Certbot 是一个 Lets Encrypt 客户端,用于管理您域的 SSL 证书。您可以使用以下命令安装 Certbot 客户端:

apt-get install python3-certbot-nginx -y

安装 Certbot 客户端后,运行以下命令为您的网站安装 Lets Encrypt SSL。

certbot --nginx -d osclass.linuxbuz.com

您将被要求提供您的电子邮件地址并接受服务条款,如下所示:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for osclass.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/osclass.conf

接下来,您还需要选择是否将 HTTP 流量重定向到 HTTPS,如下所示:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

键入 2 并按 Enter 键继续。安装证书后,您应该会看到以下输出:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/osclass.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://osclass.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=osclass.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/osclass.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/osclass.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-11-11. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 - We were unable to subscribe you the EFF mailing list because your
   e-mail address appears to be invalid. You can try again later by
   visiting https://act.eff.org.

此时,您的 Osclass 网站已使用 Lets Encrypt SSL 进行保护。

访问 Osclass

现在,打开您的 Web 浏览器并输入 URL https://osclass.linuxbuz.com。您将被重定向到以下屏幕:

单击“安装”按钮开始安装。您应该看到以下屏幕:

确保满足所有要求,然后单击“运行安装”按钮。您应该看到以下屏幕:

提供您的数据库名称、数据库用户名、密码,然后单击“下一步”按钮。您应该看到以下屏幕:

提供您的管理员用户名、密码、电子邮件,然后单击“下一步”按钮。安装完成后,您应该会看到以下屏幕:

单击“完成并转到管理面板”按钮。您将被重定向到 Osclass 登录屏幕,如下所示:

提供您的管理员用户名和密码,然后单击“登录”按钮。您应该在以下屏幕中看到 Osclass 仪表板:

结论

在本指南中,您学习了如何在 Ubuntu 20.04 服务器上安装带有 Nginx 的 Osclass cms。您还学习了如何使用 Lets Encrypt SSL 保护 Osclass。我希望您现在可以使用 Osclass 轻松创建自己的分类网站。

©2015-2025 Norria support@alaica.com