CentOS7 Nginx安装及配置反向代理
背景:
Mono (Mono JIT compiler version 5.4.0.201 )
jexus-5.8.2-x64(《CentOS7 安装 jexus-5.8.2-x64》)
VirtualBox5.1.22(3个CentOS7系统) (192.168.5.147、192.168.5.182、192.168.5.183)
参考资料:
http://www.cnblogs.com/guogangj/p/4131704.html(HappyAA服务器部署笔记1(nginx+tomcat的安装与配置))
http://www.cnblogs.com/guogangj/p/5207104.html(简易nginx TCP反向代理设置)
http://www.cnblogs.com/bass6/p/5948199.html(CNginx反向代理设置 从80端口转向其他端口)
http://www.cnblogs.com/jeffzhang/p/4664457.html(Centos 7 上使用nginx为Node.js配置反向代理时错误:(13: Permission denied) while connecting to upstream)
http://www.cnblogs.com/mfrbuaa/p/4866135.html(解决Nginx的connect() to 127.0.0.1:8080 failed (13: Permission denied) while connect)
http://www.cnblogs.com/zrbfree/p/6419043.html(nginx 安装时候报错:make: *** No rule to make target `build', needed by `default'. Stop.)
写这篇文章也是为了记录我的履试不爽的过程,怕以后很久不用就忘了,感谢园子及贡献者。
1、三个CentOS7系统准备
在147机子基础上完整复制了182及183,复制好后一样要刷新一下网络的MAC地址。
2、安装Jexus《CentOS7 安装 jexus-5.8.2-x64》本想只安装182:8888,183:7777,index.html内容设置不同,但因设置好后始终把错误:"502 Bad Gateway"
于是将147:8080也安装 上并设置
3、安装Nginx
#yum update
更新一些库和必要的支持,完了之后去下载一个nginx的最新版,如今我责编的版本是1.7.7:
#wget http://nginx.org/download/nginx-1.13.6.tar.gz
解压缩
#tar -zvxf nginx-1.13.6.tar.gz
#cd nginx-1.13.6
nginx有很多很多编译配置项,但由于我这是第一篇笔记,所以我基本上都使用了默认的配置:
#./configure --with-http_ssl_module --with-http_gzip_static_module
我只加了两个选项,--with-http_ssl_module表示使用ssl模块,--with-http_gzip_static_module表示使用gzip模块,其它更详细的配置就要参考nginx的文档了:http://nginx.org/en/docs/configure.html如果没configure成功(会显示XXX not found),那是因为有些依赖没有被正确安装.那么先安装一下这些依赖条件,通常是pcre,zlib这些,这么一下就基本上可以了:
#yum install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel#make
#make install可执行文件就会被安装在: /usr/sbin/nginx (默认配置)
nginx基本使用
程序位置:/usr/local/nginx/sbin/nginx
配置文件位置:/usr/local/nginx/conf/nginx.conf
启动nginx:
#cd /usr/local/nginx/sbin/
#./nginx如果运行的时候不带-c参数,那就采用默认的配置文件,即/etc/nginx/nginx.conf
查看运行进程状态:
# ps aux | grep nginx打开浏览器,访问http://localhost/看看nginx的默认页面:
停止nginx:
#./nginx -s stop重启nginx(配置文件变动后需要重启才能生效):
#./nginx -s reload检查配置文件是否正确:
#./nginx -t查看nginx的pid:
cat /usr/local/nginx/logs/nginx.pid查看nginx版本
$ ./nginx -v回头看编译配置
# ./nginx -V
4、Nginx配置
#vi /etc/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;events {
worker_connections 1024;
}http {
include /etc/nginx/mime.types;
default_type application/octet-stream;sendfile on;
keepalive_timeout 65;
server {
listen 80;server_name localhost;
location / {
proxy_pass http://192.168.5.147:8080;
}}
}
按上面这样配置按理应该可以访问http://192.168.5.147 显示的应该是147:8080的网页内容,但 就是报错了
于是,这才查看日志
#vi /var/log/nginx/error.log
2017/11/03 05:23:53 [crit] 1331#1331: *12 connect() to 192.168.5.147:8080 failed
(13: Permission denied) while connecting to upstream, client: 192.168.5.65, server: localhost,
request: "GET / HTTP/1.1", upstream: "http://192.168.5.147:8080/", host: "192.168.5.147"
园子中搜“(13: Permission denied) while connecting to upstream, client:”就找到原因,
type=AVC msg=audit(1509701033.988:119): avc: denied { name_connect } for pid=1331
comm="nginx" dest=8080 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket
处理:
#setsebool -P httpd_can_network_connect 1
到这里应该就正常了,反向代理的后面设置
下面是设置两个服务器
user nginx;
worker_processes 1;error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;events {
worker_connections 1024;
}http {
include /etc/nginx/mime.types;
default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;keepalive_timeout 65;
#gzip on;
upstream test {
server 192.168.5.182:8888;
server 192.168.5.183:7777;
}
server {
listen 80;
server_name localhost;location / {
proxy_pass http://test;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
}
}
nginx集群报错“upstream”directive is not allow here 错误
CentOS7 Nginx安装及配置反向代理的更多相关文章
- Nginx安装及配置反向代理
本片博客记录在ubuntu16下安装nginx,以及如何实现负载均衡 安装nginx 如果是新机器,安装相关依赖环境 sudo apt install build-essential sudo apt ...
- Nginx安装部署(反向代理与负载均衡)
一.下载安装Nginx(本文环境为windows xp 32bit环境) 下载地址:http://files.cnblogs.com/likehua/nginx-1.0.11.zip 解压nginx- ...
- 使用nginx和tomcat配置反向代理和动静分离
背景 本人主修的编程语言是Java语言,因此最开始接触的Web开发也是JSP技术.使用Java开发的Web应用需要部署在专门的服务器程序上运行,比如Tomcat.但是一般很少会有人将Tomcat作为用 ...
- CentOS 6.4下Squid代理服务器的安装与配置,反向代理
CentOS 6.4下Squid代理服务器的安装与配置 一.简介 代理服务器英文全称是Proxy Server,其功能就是代理网络用户去取得网络信息. Squid是一个缓存Internet 数据的软件 ...
- 【Asp.net Core】在 Linux 子系统中安装 nginx 并配置反向代理
上一篇鸟文中,老周已经介绍过在 Ubuntu 子系统中安装 dotnet-sdk 的方法,本文老周给大伙伴们说说安装 nginx 服务,并配置反向代理.同样,老周假设你从来没有用过 Linux,所以老 ...
- CentOS 7 安装 Nginx 配置反向代理
Linux使用Nginx Yum存储库上安装Nginx,适用于Red Hat Enterprise Linux和CentOS系统. 1.添加设置Nginx Yum存储库 在CentOS中首次安装Ngi ...
- nginx配置反向代理详细教程(windows版)
内容属于原创,如果需要转载,还请注明地址:http://www.cnblogs.com/j-star/p/8785334.html Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(I ...
- Nginx插件之openresty反向代理和日志滚动配置案例
Nginx插件之openresty反向代理和日志滚动配置案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.openresty介绍 1>.Nginx介绍 Nginx是一款 ...
- Docker 快速安装&搭建 Ngnix 环境,并配置反向代理
欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 高级架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...
随机推荐
- 微信获取企业token流程
1.获取服务商Accesstoken(每10分钟企业微信会推送一次,两个小时后过期) 2.根据suitid.accesstoken.第三方企业corpid.第三方企业permanentcode,得到第 ...
- 使用Jenkins docker镜像运行Jenkins服务
需求 使用docker技术管理Jenkins服务器.避免多次部署需要重复安装的重复工作,且可以方便迁移到新的服务器. Jenkins docker镜像 https://hub.docker.com/_ ...
- PHP 【三】
字符串变量 $txt = "Hello world!"; 创建字符串后,就可以对它操作,可以在函数中使用,或者把它存储在变量中 并置运算符 [把两个字符串值连接起来] <?p ...
- ansible 使用记录
copy: ansible server -m copy -a 'src=/etc/ansible/port/iptables dest=/etc/sysconfig/iptables owner=r ...
- 【原创】大数据基础之Spark(8)Spark中Join实现原理
spark中join有两种,一种是RDD的join,一种是sql中的join,分别来看: 1 RDD join org.apache.spark.rdd.PairRDDFunctions /** * ...
- 【原创】大数据基础之Spark(5)Shuffle实现原理及代码解析
一 简介 Shuffle,简而言之,就是对数据进行重新分区,其中会涉及大量的网络io和磁盘io,为什么需要shuffle,以词频统计reduceByKey过程为例, serverA:partition ...
- 【原创】大数据基础之Ambari(2)通过Ambari部署ElasticSearch(ELK)
ambari2.7.3(hdp3.1) 安装 elasticsearch6.3.2 ambari的hdp中原生不支持elasticsearch安装,下面介绍如何通过mpack方式使ambari支持el ...
- 如何在python脚本下启动django程序
直接上图
- mybatis 保存对象 参数类型
简单介绍:保存单个对象 ,参数类型的设置,正常的话应该设置成对应的pojo,我想起了以前,不懂事时候的一个做法,其实那时候刚接触到mabatis,做新增的时候,直接就是把需要插入表中的值,放到map里 ...
- laravel whereDoesntHave
select * from `feeds` where not exists (select * from `black_lists` where `feeds`.`user_id` = `black ...