码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS7 yum 安装 Nginx最新版本

时间:2017-11-17 13:23:41      阅读:743      评论:0      收藏:0      [点我收藏+]

标签:centos7 yum 安装 nginx最新版本

下载对应当前系统版本的nginx包(package)
# wget  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm


建立nginx的yum仓库
# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm


下载并安装nginx
# yum install nginx


启动nginx服务
systemctl start nginx


配置
默认的配置文件在 /etc/nginx 路径下,使用该配置已经可以正确地运行nginx;如需要自定义,修改其下的 nginx.conf 等文件即可。


测试

在浏览器地址栏中输入部署nginx环境的机器的IP,如果一切正常,应该能看到如下字样的内容。



  1. user  nginx;  

  2. worker_processes  1;  

  3.   

  4. error_log  /var/log/nginx/error.log warn;  

  5. pid        /var/run/nginx.pid;  

  6.   

  7.   

  8. events {  

  9.     worker_connections  1024;  

  10. }  

  11.   

  12.   

  13. http {  

  14.     include       /etc/nginx/mime.types;  

  15.     default_type  application/octet-stream;  

  16.   

  17.     log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘  

  18.                       ‘$status $body_bytes_sent "$http_referer" ‘  

  19.                       ‘"$http_user_agent" "$http_x_forwarded_for"‘;  

  20.   

  21.     access_log  /var/log/nginx/access.log  main;  

  22.   

  23.     sendfile        on;  

  24.     #tcp_nopush     on;  

  25.   

  26.     keepalive_timeout  65;  

  27.   

  28.     #gzip  on;  

  29.   

  30.     #include /etc/nginx/conf.d/*.conf;  

  31.       

  32.      #设定负载均衡服务器列表  

  33.     upstream group1{  

  34.         #后端服务器访问规则  

  35.         #ip_hash;  

  36.         #weight参数表示权重值,权值越高被分配到的几率越大  

  37.           

  38.         #PC_Local  

  39.         server 192.168.187.133:80 weight=5;  

  40.           

  41.         #PC_Server  

  42.         server 192.168.187.134:80 weight=5;  

  43.           

  44.           

  45.     }  

  46.   

  47.       

  48.     server {  

  49.         listen       81;                #设置对外端口  

  50.         server_name  192.168.187.133 ;  #设置识别请求域名  

  51.         location / {  

  52.           

  53.             #定义服务器的默认网站根目录位置  

  54.             #root html;  

  55.               

  56.             #定义首页索引文件的名称  

  57.             #index index.html index.htm index.php;  

  58.               

  59.             proxy_pass  http://group1 ; #分流到group1集群  

  60.         }  

  61.     }  

  62. }  



本文出自 “爱生活的小白” 博客,请务必保留此出处http://sf1314.blog.51cto.com/13295031/1982735

CentOS7 yum 安装 Nginx最新版本

标签:centos7 yum 安装 nginx最新版本

原文地址:http://sf1314.blog.51cto.com/13295031/1982735

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!