|
本帖最后由 Jerr-_- 于 2019-2-25 13:59 编辑
写在最前面:
这或许是我在恩山论坛发的最后一篇教程类的文章了。为什么?寒心了。再一次发现文章被抄袭,真的是没什么想说的了。http://aisoa.cn/post-2371.html这篇文章和本文几乎一模一样(仅仅去掉了本文中的所有引用、参考的链接),最后还大言不惭“本文固定链接:http://aisoa.cn/post-2371.html 转载请注明:2019年02月16日于爱搜啊博客发表”。
高尚是高尚者的墓志铭,卑鄙是卑鄙者的通行证。我叫不醒装睡的人,但我可以选择用脚投票。本文有几处明显的错误,我也懒得改了,观众自己把下文中的caddy换成www-data吧。
前言——什么是LNMP
使用镜像:debian9,Armbian_5.73,5.0内核。https://yadi.sk/d/pHxaRAs-tZiei/5.73/S905_NEXT/Armbian_5.73_Aml-s905_Debian_stretch_next_5.0.0-rc4-next-20190130-g02495e76d-dirty.img.xz
本教程为思考性质的文章,可建立可内网访问的一个小小的博客网站用于写写日记什么的,学会方法后可自己租vps建网站供大家浏览。本教程亲测成功,上截图
本文改编自我自己的文章:https://jerryding.site/website/ ,真正要vps上建网站看这篇文章吧,caddy更好用。
参考链接:https://www.digitalocean.com/com ... l-nginx-on-debian-9——>nginx部分参考这里https://blog.yangmame.org/%E6%9E%81%E9%99%90%E5%BB%BA%E7%AB%99.html——>大部分内容转载自这里,我做的仅仅是简化了一下他的内容,更容易看懂。
首先,说说建站需要准备什么:
- 一个域名(可以不要,直接输入ip来访问网站,不推荐)——因为我们用N1做实验,直接在内网访问,所以不要域名了。
- 一个tls,本文以cloudflare为例,用于加速访问/保护网站。
- 一个公网ip(没有的话可以动态域名解析、内网穿透,不在本文讨论范围中)
- 一台vps服务器——本文用的N1
然后,再说说基本思路。搭建一个简单的动态网站,需要以下内容:
- 一台服务器(Linux系统)
- 网站服务,一般用三个下面中的一个:
- apache——读作“阿帕奇”
- nginx——读作“引擎X”(N1用这个)
- caddy——读作“凯蒂”(这个最好使,vps选他!)
- 一个数据库(mysql)
- php解释语言。
- 网站主体部分,本文以wordpress为例。
如果需要其他服务,自行搭建即可。
本文主要讲解使用LCMP(linux+caddy+mysql+php)方式搭建网站,因为caddy能够自动申请ssl证书并自动续签,很方便。服务器租赁,域名购买,cloudfare注册配置,域名解析这些部分都很简单,随便搜索一下就有,这里不再赘述。
L——>debian 9
服务器的系统,我们选择debian 9。
Debian(/ˈdɛbiən/[)是完全由自由软件组成的类UNIX操作系统,其包含的多数软件使用GNU通用公共许可协议授权,并由Debian计划的参与者组成团队对其进行打包、开发与维护。 作为最早的Linux发行版之一,Debian在创建之初便被定位为在GNU计划的精神指导下进行公开开发并自由发布的项目。
——摘自维基百科
apt update && apt upgrade -y #升级系统软件包
N——>nginx——摘自维基百科
安装nginx
apt update
apt install nginx
测试
systemctl start nginx
然后在浏览器输入你N1的ip地址,会显示nginx运行成功。
修改配置文件
vim /etc/nginx/sites-enabled/default
修改这些加粗的地方:
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/ ... ls/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.php index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
重启nginx
systemctl restart nginx
M——>MariaDB (MySQL的开源分支)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。
——摘自维基百科
按照下面内容进行安装,注意修改黑体字内容。
apt install mysql-server -y
mysql_secure_installation
mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
P——>php7.3
PHP(全称:PHP:Hypertext Preprocessor,即“PHP:超文本预处理器”)是一种开源的通用计算机脚本语言,尤其适用于网络开发并可嵌入HTML中使用。PHP的语法借鉴吸收C语言、Java和Perl等流行计算机语言的特点,易于一般程序员思考。PHP的主要目标是允许网络开发人员快速编写动态页面,但PHP也被用于其他很多领域。
——摘自维基百科
debain9想要安装php7.3,需要先添加软件源:
apt install ca-certificates apt-transport-https -y
wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | tee /etc/apt/sources.list.d/php.list
apt update
apt install php7.3-fpm -y
apt install php7.3 php7.3-mysql php7.3-gd php7.3-xml php7.3-cgi php7.3-cli php7.3-curl php7.3-zip php7.3-mbstring unzip -y
启动服务
systemctl enable php7.3-fpm
systemctl start php7.3-fpm
最后,把前面修改过配置文件服务重启一下,确保配置文件正确读取
systemctl restart nginx
systemctl restart php7.3-fpm
至此,LNMP就搭建完了,这是我们之后再添加各种服务(自建网盘/博客/论坛/等等等等)的基础。先演示一下搭建最简单的博客Wordpress吧。
WordPress
With our famous 5-minute installation, setting up WordPress for the first time is simple. We’ve created a handy guide to see you through the installation process.
wordpress以操作简单,“五分钟安装”而著称。具体操作可看上面的英文链接的官方指南。太长不看的话直接用我下面的命令即可。
还是自己替换黑体字:
mkdir /var/www/wordpress
cd /var/www/wordpress
wget https://wordpress.org/latest.tar.gz
tar xvf latest.tar.gz
mv wordpress/* .
rm wordpress/ -rf
chown caddy:caddy /var/www/wordpress
现在,使用浏览器访问你的网站,按提示输入之前建立的数据库名和密码,恭喜你建站成功。之后可以自己在浏览器里面修改网站的主题、页面等等。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
评分
-
查看全部评分
|