首页 > 其他 > 详细

nginx安装

时间:2019-03-19 15:55:09      阅读:116      评论:0      收藏:0      [点我收藏+]

安装nginx服务
1.1 第一个里程:进行nginx软件下载
cd /install
wget http://nginx.org/download/nginx-1.12.2.tar.gz
第二里程碑:安装依赖软件
yum install -y pcre-devel openssl-devel
1.2 第三个里程:解压软件,创建虚拟用户,进行编译安装(三步曲)
命令:(解压)tar xf nginx-1.12.2.tar.gz 
命令:(检查)ll /server/tools
drwxr-xr-x 8 1001 1001 4096 Oct 17 21:16 nginx-1.12.2
-rw-r--r-- 1 root root 981687 Oct 17 21:20 nginx-1.12.2.tar.gz
命令:(切换)cd nginx-1.12.2/
命令:(查看路径)pwd
/server/tools/nginx-1.12.2
命令:(创建虚拟管理用户)useradd -s /sbin/nologin -M www
命令:(创建)nginx命令安装的所在地
命令:(创建)mkdir -p /application/nginx-1.12.2/
编译第一步曲:进行配置(/server/tools/nginx-1.12.2)
./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
1.2.1 配置参数说明:
--prefix=PATH set installation prefix
指定软件程序安装的路径信息
--user=USER set non-privileged user for
worker processes
创建一个虚拟用户,用于管理nginx服务的worker进程
--group=GROUP set non-privileged group for
worker processes
创建一个虚拟用户组,用于管理nginx服务的worker进程
--with-http_ssl_module enable ngx_http_ssl_module
让nginx服务可以支持https访问
--with-http_stub_status_module enable ngx_http_stub_status_module
便于监控软件监视nginx服务运行状态
1.3 编译第二步曲:编译(翻译)
说明:编译过程实质是将各种程序语言转换为系统可以识别的二进制信息
命令:(把代码---->二进制)make
1.4 编译第三步曲:编译安装
命令:(安装)make install
1.5 第四个里程碑:创建程序目录软链接文件
命令:(创建软连接)cd /application/ && ln -s /application/nginx-1.12.2/ /application/nginx
命令:(检查)ll /application/
total 4
lrwxrwxrwx 1 root root 26 Feb 2 17:14 nginx -> /application/nginx-1.12.2/
drwxr-xr-x 6 root root 4096 Feb 2 17:13 nginx-1.12.2
1.6 第五个里程碑:网站服务启动成功
命令:(启动nginx服务)/application/nginx/sbin/nginx
1.7 第六个里程碑:检查测试
命令:(检查进程是否开启)ps -ef |grep nginx
root 6948 1 0 17:17 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
www 6949 6948 0 17:17 ? 00:00:00 nginx: worker process 
root 6951 1279 0 17:17 pts/1 00:00:00 grep nginx
说明:master进程表示nginx主进程,负责nginx服务的启动 停止等操作
worker进程表示真正处理用户请求的进程
命令:(检查80端口是否开启)netstat -lntup|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12684/nginx 
检查nginx软件是否安装成功
windows  39.96.209.11
欢迎使用nginx的界面

!!!!!!第七个里程碑(基于域名的虚拟主机配置)
[root@web01 conf]# pwd
/application/nginx/conf 路径
#进行nginx的配置文件的备份
命令:(备份)cp nginx.conf{,.bak}
#进行nginx的配置文件的简化
命令:(简化)
[root@web01 conf]# vim nginx.conf (配置nginx的配置文件的主配置文件)

worker_processes 1;

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.huchangxi.com;
root html/www;
index index.html index.htm;
}
}

第八个里程碑(网站目录和文件环境准备)
[root@web01 nginx]# mkdir /application/nginx/html/www -p 创建目录
[root@web01 nginx]# echo "39.96.209.111 hua" > /application/nginx/html/www/index.html 创建内容
[root@web01 nginx]# cat /application/nginx/html/www/index.html

39.96.209.111 hua

查看创建结果
第九个里程碑(检查配置文件语法,进行服务重启或者启动)
[root@web01 conf]# /application/nginx/sbin/nginx -t 检查语法
nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful
[root@web01 conf]# /application/nginx/sbin/nginx 启动
第十个里程碑(利用curl或者浏览器进行访问测试)
需要对虚拟主机域名进行解析(编写hosts文件-linux/ windows里面hosts)
#添加www的解析
命令:(添加)vim /etc/hosts 
39.96.209.111 hua

第十一个里程碑(设置开机自启nginx服务)
#把启动nginx的命令添加到/etc/rc.local开启自启动里
命令: vim /etc/rc.local
/application/nginx/sbin/nginx
当客户端访问nginx服务端,返回的状态码信息为304时,表示进行读取缓存处理
(nginx服务配置结束)

技术分享图片

nginx安装

原文:https://www.cnblogs.com/A121/p/10559020.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!