1.安装各种依赖#gcc安装,nginx源码编译需要yuminstallgcc-c++#PCREpcre-devel安装,nginxhttp模块使用pcre解析正则表达式yuminstall-ypcrepcre-devel#zlib安装,nginx使用zlib对http包的内容进行gzipyuminstall-yzlibzlib-devel#OpenSSL安装,一个强大的安全套接字层密码库,nginx不仅支持http协议,还支持https(即在ssl上传输http协议)yuminstall-yopensslopenssl-devel2。下载1)直接官网下载【官网链接】2)使用wget命令下载(推荐)#下载版本号可以根据当前官网最新稳定版本调整wget-chttps://nginx.org/download/nginx-1.16.1.tar.gz3.安装#根目录使用ls命令查看下载的nginx压缩包,然后解压tar-zxvfnginx-1.16.1.tar.gz#解压并进入directorycdnginx-1.16.1#使用默认配置./configure#编译安装makemakeinstall#找到安装路径,默认是这个路径[root@nice-setc]#whereisnginxnginx:/usr/local/nginx#启动和停止nginxcd/usr/local/nginx/sbin/./nginx#启动./nginx-sstop#停止,直接找到nginx进程id然后用kill命令强行杀掉进程./nginx-squit#退出stop,等待nginx进程完成任务再停止。/nginx-sreload#重新加载配置文件,修改nginx.conf后使用该命令,新配置生效#重启nginx,就是建议先停止,再启动。/nginx-sstop./nginx#Viewnginx进程返回如下,表示成功[root@nice-setc]#psaux|grepnginxroot247420.00.1206801200?SS09:470:00nginx:主进程./nginxnobody269330.00.1211041684?S10:570:00nginx:workerprocessroot271480.00.0112708980pts/0R+11:430:00grep--color=自动启动nginx4。#在rc.local中增加启动代码vi/etc/rc.local#添加一行/usr/local/nginx/sbin/nginx添加后保存#设置执行权限cd/etcchmod755rc.localbrowserenterserverip即可看到nginx欢迎界面5.配置域名映射#进入nginx配置文件目录,找到nginx配置文件nginx.confcd/usr/local/nginx/conf/#直接修改vinginx.conf#设置实际服务器列表upstreamtest_server{server127.0.0.1:8080;}#HTTPserverserver{#监听80端口,80端口是知名端口号,用于HTTP协议listen80;#定义使用www.test.com域名访问server_namewww.test.com;#反向代理的路径(绑定到upstream),在locationlocation/{proxy_passhttp://test_server;后设置映射路径;}location/{rootusr/local/nginx/test;索引/index.html;try_files$uri$uri//index.html;}}需要修改server_name和location的内容#修改完成后,重新加载配置文件cd/usr/local/nginx/sbin/./nginx-sreload
