centos7安装Nginx、使用nginx记录

一、安装各类依赖html

#gcc安装,nginx源码编译须要
yum install gcc-c++

#PCRE pcre-devel 安装,nginx 的 http 模块使用 pcre 来解析正则表达式
yum install -y pcre pcre-devel

#zlib安装,nginx 使用zlib对http包的内容进行gzip
yum install -y zlib zlib-devel

#OpenSSL 安装,强大的安全套接字层密码库,nginx 不只支持 http 协议,还支持 https(即在ssl协议上传输http)
yum install -y openssl openssl-devel

二、下载
(1)直接官网下载【官网连接】
当前稳定版本是1.16.1
(2)使用wget命令下载(推荐)nginx

#下载版本号可根据目前官网最新稳定版自行调整
wget -c https://nginx.org/download/nginx-1.16.1.tar.gz

三、安装c++

#根目录使用ls命令能够看到下载的nginx压缩包,而后解压
tar -zxvf nginx-1.16.1.tar.gz

#解压后进入目录
cd nginx-1.16.1

#使用默认配置
./configure

#编译安装
make
make install

#查找安装路径,默认都是这个路径
[root@VM_0_12_centos ~]# whereis nginx
nginx: /usr/local/nginx

#启动、中止nginx
cd /usr/local/nginx/sbin/
./nginx     #启动
./nginx -s stop  #中止,直接查找nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit  #退出中止,等待nginx进程处理完任务再进行中止
./nginx -s reload  #从新加载配置文件,修改nginx.conf后使用该命令,新配置便可生效

#重启nginx,建议先中止,再启动
./nginx -s stop
./nginx

#查看nginx进程,以下返回,即为成功
[root@VM_0_12_centos ~]# ps aux|grep nginx
root      5984  0.0  0.0 112708   976 pts/1    R+   14:41   0:00 grep --color=auto nginx
root     18198  0.0  0.0  20552   612 ?        Ss   11:28   0:00 nginx: master process ./nginx
nobody   18199  0.0  0.0  23088  1632 ?        S    11:28   0:00 nginx: worker process

四、开机自启动正则表达式

#在rc.local增长启动代码便可
vi /etc/rc.local
#增长一行 /usr/local/nginx/sbin/nginx,增长后保存
#设置执行权限
cd /etc
chmod 755 rc.local

浏览器输入服务器ip便可看到nginx欢迎界面shell

五、配置域名映射centos

#进入nginx配置文件目录,找到nginx的配置文件nginx.conf
cd /usr/local/nginx/conf/

#直接修改
vi nginx.conf

在文件中找到如图位置 浏览器

#listen为监听的端口
listen       80;
#server_name为域名
server_name  www.test.com;
#location是访问地址的设置,locahost也能够用服务器ip代替
location / {
proxy_pass http://localhost:8080; 
}

如图,只须要修改server_name和location里面的内容便可 安全

#修改完成后,从新加载配置文件
cd /usr/local/nginx/sbin/
./nginx -s reload

六、进入域名控制台,添加或者修改解析地址,若是原来配置了解析,新解析须要必定时间才能生效服务器

相关文章
相关标签/搜索