Centos7 安装Nginx1.14.2配置反向代理和开机自启详细教程
2019-03-29 13:08
435 查看
安装Nginx
创建虚拟机
ps -ef | grep nginx
root 7195 7178 0 14:19 pts/0 00:00:00 grep --color=auto nginx
将nginx放入该目录,解压
[root@localhost leyou]# tar xvf nginx-1.14.2.tar.gz
删除压缩包
[root@localhost leyou]# rm -rf nginx-1.14.2.tar.gz
进去nginx目录
[root@localhost leyou]# cd nginx-1.14.2/
报错安装gcc
yum -y install gcc
安装pcre-devel
yum -y install pcre-devel
安装zlib-devel
yum -y install zlib-devel
指定安装目录/opt/nginx
[root@localhost nginx-1.14.2]# ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
安装nginx
make && make install
启动nginx
[root@localhost nginx-1.14.2]# nginx
查看进程
[root@localhost nginx-1.14.2]# ps -ef | grep nginxroot 11158 1 0 14:52 ? 00:00:00 nginx: master process nginx nobody 11159 11158 0 14:52 ? 00:00:00 nginx: worker process root 11161 7178 0 14:52 pts/0 00:00:00 grep --color=auto nginx
关闭防火墙(选)
查看防火墙状态: systemctl status firewalld.service 执行关闭命令: systemctl stop firewalld.service 再次执行查看防火墙命令:systemctl status firewalld.service 执行开机禁用防火墙自启命令 : systemctl disable firewalld.service
开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent 加载 firewall-cmd --reload 重启防火墙: systemctl stop firewalld.service systemctl start firewalld.service 配置前先确保防火墙是运行着的 firewall-cmd --state 开启防火墙 service firewalld start
访问nginx
http://192.168.25.128/
开机自启
vi /usr/lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/bin/nginx ExecReload=/usr/bin/nginx -s reloadExecStop=/usr/bin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl enable nginx.service
修改nginx.conf配置文件,配置反向代理
server { listen 80; server_name manage.leyou.com; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://192.168.1.141:9001; #代理地址 proxy_connect_timeout 600; proxy_read_timeout 600; } } server { listen 80; server_name api.leyou.com; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_pass http://192.168.1.141:10010; proxy_connect_timeout 600; proxy_read_timeout 600; } }
重新加载nginx配置文件
nginx -s reload
相关文章推荐
- Linux(Red Hat Enterprise)下安装nginx与sticky模块,并配置开机自启动图文教程
- Centos7配置本地Yum源,开机自动挂载之详细教程
- Nginx安装及配置详细教程
- Centos7安装jdk8+zookeeper+tomcat9开机自启详细教程
- Centos7安装Redis5详细教程并配置自启动
- CentOS7安装Nginx1.10.1详细图解教程
- centos7系统下nginx安装并配置开机自启动操作
- Windows Server 2016 Nginx 安装配置详细图文教程
- Centos7安装Nginx及配置反向代理和负载均衡
- RedHat7.4或CentOS7.4安装Nginx1.14.2详细教程,含安装包及依赖包
- Cubieboard A10 安装Nand系统,配置nginx,php,mysql,samba详细教程
- centos7系统下nginx安装并配置开机自启动操作
- CentOS (6.6) Nginx (1.14.0) 安装配置 详细教程
- FastDFS安装与nginx反向代理配置
- 人体姿态估计Alphapose配置安装教程(GPU,超详细,亲测有效!)
- 在centos7中安装mariaDB-详细教程
- nginx详细文档 – 安装配置,深入源码,模块编写,编译器参数,系统函数
- kafka_2.10-0.8.1.1.tgz的1或3节点集群的下载、安装和配置(图文详细教程)绝对干货
- Linux 安装Nginx详细图解教程
- Linux下安装Nginx详细图解教程