云服务器Linux网站搭建-配置环境
本人云服务器基础配置为:CentOS 8.2 64位
本次安装包括: nginx、php、mysql、node
nginx
1. 安装-源码安装
官网下载地址: nginx: download
# 进入存放源码压缩包的目录, 可自己指定或新建
cd /home/download
# 如需创建目录
mkdir download
# 下载, 可在官网下载地址查找最新版nginx下载链接
wget http://nginx.org/download/nginx-1.26.0.tar.gz
# 解压
tar -zxvf nginx-1.26.0.tar.gz
# 查看解压后的文件夹,如图1
ls -l
# 进入解压文件夹 nginx-1.26.0
cd nginx-1.26.0
# 查看当前目录, 如图2
ls -l
# 执行 configure 进行配置得到 Makefile 文件
# --prefix 代表安装的路径,这里使用 /usr/local/nginx-1.26.0
# --with-http_ssl_module 安装ssl
# --with-http_stub_status_module查看nginx的客户端状态
./configure --prefix=/usr/local/nginx-1.26.0 --with-http_ssl_module --with-http_stub_status_module
# 编译并安装
make & make install
# 可在指定的安装目录中 /usr/local/ 看到 nginx-1.26.0 文件夹, 如图3
cd /usr/local/
ls -l
# 进入目录 nginx-1.26.0 其中如图4
# conf 配置目录
# html 默认网站根目录
# logs 日志目录
# sbin 可执行程序目录
cd nginx-1.26.0
ls -l
# 至此安装完成
2. 启动nginx
# 1. 直接启动, 运行 sbin 目录下可执行文件 nginx
/usr/local/nginx-1.26.0/sbin/nginx
# 2. 使用命令启动 ( 推荐 )
nginx # 回车即可,需提前配置环境变量
# 环境变量配置: 将 nginx 可执行程序目录加入 环境变量 PATH 中
# 有多种方法,此处使用针对所有用户永久有效的方式: 编辑文件 /etc/profile
nano /etc/profile # 或使用其他编辑器如: vim /etc/profile
# 在最后一行加上
export NGINX_PATH=/usr/local/nginx-1.26.0/sbin # 即上问所述 nginx 可执行程序目录
export PATH=$PATH:$NGINX_PATH # 使用 $PATH 保留原有变量
# 编辑后文件如 图5 所示, 保存并刷新环境变量
source /etc/profile
# 测试环境变量配置
nginx -v
# nginx 常用命令
nginx # 启动
nginx -v # 查看版本
nginx -s stop # 强制退出
nginx -s quit # 正常退出
nginx -s reload # 重新加载
nginx -s reopen # 重新打开
3. nginx配置
访问网站 ip:80
如公网 ip 为 117.72.74.78, 则访问网址 http://117.72.74.78:80
修改配置文件以访问自己的网站
# 编辑配置文件
nano /usr/local/nginx-1.26.0/conf/nginx.conf
# 在 http 块下存在 server 如 图7 , 其中
listen 80 # 监听 80 端口
server_name localhost # 主机名
location / {
root html; # 根目录, 此处路径相对 /usr/local/nigin-1.26.0/,也可使用绝对路径
index index.html index.htm; # 主页文件 即直接访问ip后跳转的文件
}
# 修改 root 和 index 项即可访问自己的代码
php
1. 安装php
未完待续…