温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CentOS Nginx服务器怎么配置nginx.conf

发布时间:2021-08-13 10:07:25 来源:亿速云 阅读:141 作者:chen 栏目:系统运维

这篇文章主要介绍“CentOS Nginx服务器怎么配置nginx.conf”,在日常操作中,相信很多人在CentOS Nginx服务器怎么配置nginx.conf问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”CentOS Nginx服务器怎么配置nginx.conf”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

在向大家详细介绍CentOS Nginx之前,首先让大家了解下CentOS Nginx,然后全面介绍CentOS Nginx,希望对大家有用。CentOS Nginx 已经是目前公认的效率很高的代理服务,同时可以用来做负载均衡

由于项目目前只有一台CentOS Nginx 的服务器,无法用来测试,所以打算找下Nginx windows下版本;http://www.kevinworthington.com/nginx/win32/以上为win32的版本用户访问 sp.imichat.com 均衡到 10.10.10.181:8080; 10.10.10.181:8081; 10.10.10.181:8082; 这3台服务器CentOS Nginx

配置CentOS Nginx 的nginx.conf

http {}增加如下内容  upstream sp.imichat.com   {server 10.10.10.181:8080;   server 10.10.10.181:8081;   server 10.10.10.181:8082; }  server {} 修改异侠信息:   listen 80;   server_name sp.imichat.com;  #charset koi8-r;  #access_log logs/host_access_log main;   location / {  proxy_pass http://sp.imichat.com;  proxy_set_header Host $host;  proxy_set_header X-Real-IP $remote_addr;  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  }   access_log logs/sp.imichat.com.log combined;  [/code]

启动181上的3个tomcat,修改tomcat首页加入端口信息,以用来清晰看到当前分配到那台tomcat启动Nginx,访问 http://sp.imichat.com/可看到请求被发送到3台服务器。

抓http包可看到request为

GET / HTTP/1.1  Host: sp.imichat.com  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  Accept-Language: en-us,zh-cn;q=0.5  Accept-Encoding: gzip,deflate  Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7  Keep-Alive: 300  Connection: keep-alive  Cookie: JSESSIONID=A75E09D2EBF769A7BD95195E29DE87DE; key=1227008000183; memberName=admin; memberType=%7C%u8D85%u7EA7%u7BA1%u7406%u5458%7C  Pragma: no-cache  Cache-Control: no-cache

response:

HTTP/1.1 200 OK  Server: nginx/0.7.21-win32  Date: Tue, 18 Nov 2008 12:12:33 GMT  Content-Type: text/html  Connection: keep-alive  ETag: W/"8157-1227009260637"  Last-Modified: Tue, 18 Nov 2008 11:54:20 GMT  Content-Length: 8157

到此,关于“CentOS Nginx服务器怎么配置nginx.conf”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI