仅供参考, 不同系统操作可能会不一样, 中间遇到错误, 找一下错误原因, 一般是单词”error“后的一句, 复制, 百度, vim操作下面有注释
首先是域名解析到指定的服务器
安装nginx
- 方法一:这个是最简单的方法,但是很有可能会失败,这里搞定了就能直接去配置nginx了
1.安装g++a | sudo apt-get install g++ |
---|---|
2.使用apt直接安装 | sudo apt-get install nginx |
3.启动 | service nginx start |
-
方法二
-
下载nginx及相关组件输入 :
cd /usr/local/src/ wget http://nginx.org/download/nginx-1.10.2.tar.gz wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz wget http://zlib.net/zlib-1.2.11.tar.gz wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
AI 代码解读 -
安装c++编译环境
yum install gcc-c++ 或者 apt-get install g++ 中间需要确认一次, 输入: y
AI 代码解读 -
安装nginx及相关组件
- 安装openssl:
tar zxvf openssl-fips-2.0.10.tar.gz cd openssl-fips-2.0.10 ./config && make && make install cd /usr/local/src/ 或者 cd .. 回到src文件夹中
AI 代码解读- 安装pcre: tar zxvf pcre-8.40.tar.gz
cd pcre-8.40 ./configure && make && make install cd /usr/local/src/ 或者 cd .. 回到src文件夹中
AI 代码解读- 安装zlib: tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11 ./configure && make && make install cd /usr/local/src/ 或者 cd .. 回到src文件夹中
AI 代码解读- 安装nginx : tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2 ./configure && make && make install
AI 代码解读
-
启动 nginx
-
先找到nginx的安装位置, 输入:
whereis nginx # 得到路径 例如: /usr/local/nginx
AI 代码解读 -
进入得到的路径:
cd /usr/local/nginx
AI 代码解读 -
启动 :
/usr/local/nginx/sbin/nginx 或者 cd /usr/local/nginx/sbin/ 输入: nginx 或 ./nginx
AI 代码解读 -
查看启动状态:
ps -aux | grep nginx 出现三条记录就表示已经启动成功
AI 代码解读如果启动成功, 不改配置文件打开自己的域名也能看到一个默认页面, 说明域名已经绑定成功
配置nginx
-
进入nginx配置文件夹
whereis nginx # 得到路径 例如: /usr/local/nginx cd /usr/local/nginx
AI 代码解读 -
打开配置文件
vim nginx.conf
AI 代码解读 - 找到如图所示的地方, 位置和文件名称改为自己需要展示的网页
注释
- nginx操作命令:
-
启动
/usr/local/nginx/sbin/nginx
AI 代码解读 -
停止/重启
/usr/local/nginx/sbin/nginx -s stop(quit、reload)
AI 代码解读 -
命令帮助
/usr/local/nginx/sbin/nginx -h
AI 代码解读 -
验证配置文件
/usr/local/nginx/sbin/nginx -t
AI 代码解读 -
配置文件
vim /usr/local/nginx/conf/nginx.conf
AI 代码解读 -
vim简单操作命令: 深入了解百度
开启编辑:按“i”或者“Insert”键 退出编辑:“Esc”键 退出vim:“:q” 保存vim:“:w” 保存退出vim:“:wq” 不保存退出vim:“:q!”
AI 代码解读 -
查看当前系统版本, 输入:
cat /etc/redhat-release 或 : lsb_release -a
AI 代码解读参考链接:时光不写博客-nginx的安装和配置