http://nginx.org/download/ 下载对应的Nginx

安装nginx之前需要安装依赖包

yum install gcc gcc-c++ zlib-devel pcre-devel openssl-devel openssl-libs

cd /usr/local/src

我下载的是最新稳定版本  nginx-1.8.0.tar.gz

下载下来后解压

tar -zxvf nginx-1.8.0.tar.gz

文件夹下就有个nginx的文件夹

cd  nginx-1.8.0

./configu              --配置安装nginx的路径

make                   --编译

make install        --安装

安装成功之后记得 在cd /usr/local/nginx/sbin   ./nginx启动

./nginx -s reload 重启nginx

./nginx -s stop   停掉

配置   vi /usr/local/nginx/conf/nginx.conf

#user nobody;
worker_processes 2;
 
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
 
#pid    logs/nginx.pid;
 
 
events {
  accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
  multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
  worker_connections 1024;#最大连接数
}
 
 
http {
  include    mime.types;#文件扩展名与文件类型映射表,此映射表主要用于部署在本nginx上的静态资源
  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 logs/access.log main;
 
  sendfile    on;
  #tcp_nopush   on;
 
  #keepalive_timeout 0;
  keepalive_timeout 65;#连接超时时间
 
  gzip on;
 
  #反向代理
 
  #【配置1】此配置是[配置4]和[配置5]的结合
  #此配置将请求转发到两个WEB服务器,根据客户端IP分配目标主机,同时按权重分配流量
  upstream app1 {
    ip_hash;
    server 192.168.14.132:8080 weight=5;
    server 192.168.14.133:80 weight=3;
  }
 
  #【配置2】
  #默认负载平衡配置,nginx应用HTTP负载平衡来分发请求。
  #upstream app1 {
  #  server 192.168.14.132:8080;
  #  server 192.168.14.133:80;
  #}
 
  #【配置3】
  #最小连接负载平衡配置,nginx将尽量不使用繁忙的服务器,而是将新请求分发给不太忙的服务器。
  #upstream app1 {
  #  least_conn;
  #  server 192.168.14.132:8080;
  #  server 192.168.14.133:80;
  #}
 
  #【配置4】
  #会话持久性配置,使用ip-hash,客户端的IP地址用作散列密钥,
  #以确定应为客户端请求选择服务器组中的哪个服务器。
  #此方法确保来自同一客户端的请求将始终定向到同一服务器,除非此服务器不可用。
  #upstream app1 {
  #  ip_hash;
  #  server 192.168.14.132:8080;
  #  server 192.168.14.133:80;
  #}
 
  #【配置5】
  #加权负载平衡配置,通过使用服务器权重进一步影响nginx负载平衡算法。
  #未配置权重的服务器,意味着所有指定的服务器被视为对特定负载平衡方法同等资格。
  #upstream app1 {
  #  ip_hash;
  #  server 192.168.14.132:8080 weight=3;
  #  server 192.168.14.133:80 weight=2;
  #  server 192.168.14.134:80;
  #  server 192.168.14.135:80;
  #}
 
 
  server {#可配置多个server以监听不同IP和不同端口
    listen    80;#监听的端口
    server_name localhost;#监听的服务器
 
    #charset koi8-r;
 
    #access_log logs/host.access.log main;
 
    #反斜杆代表所有连接,此配置目的是将所有连接交给名为app1的upstream代理,实现负载平衡
    location / {
      proxy_pass http://app1;
    }
 
    #图片文件路径,一般来说,静态文件会部署在本机以加快响应速度
    #可配置多个这样的location,满足各种需求
    location ~\.(gif|jpg|png)$ {
      root /home/root/images;
    }
 
    location ~\.(iso|zip|txt|doc|docx)$ {
      root /home/root/files;
    }
 
 
    #error_page 404       /404.html;
 
    # redirect server error pages to the static page /50x.html
    #
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
      root  html;
    }
 
 
    # FastCGI是CGI全称是“公共网关接口”(Common Gateway Interface)
    #对于我来说,使用Tomcat代替即可,请忽略此配置。
    #location ~ \.php$ {
    #  root      html;
    #  fastcgi_pass  127.0.0.1:9000;
    #  fastcgi_index index.php;
    #  fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    #  include    fastcgi_params;
    #}
 
    # 添加黑名单,禁止某某访问特定文件
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #  deny all;
    #}
  }
 
 
  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  #  listen    8000;
  #  listen    somename:8080;
  #  server_name somename alias another.alias;
 
  #  location / {
  #    root  html;
  #    index index.html index.htm;
  #  }
  #}
 
 
  # HTTPS server
  #
  #server {
  #  listen    443 ssl;
  #  server_name localhost;
 
  #  ssl_certificate   cert.pem;
  #  ssl_certificate_key cert.key;
 
  #  ssl_session_cache  shared:SSL:1m;
  #  ssl_session_timeout 5m;
 
  #  ssl_ciphers HIGH:!aNULL:!MD5;
  #  ssl_prefer_server_ciphers on;
 
  #  location / {
  #    root  html;
  #    index index.html index.htm;
  #  }
  #}
 
}
 
配置完之后重启nginx
cd /usr/local/nginx/sbin      ./nginx -s reload
如果重启之后访问不了nginx服务器的话  
查看是否是防火墙没有开启端口
firewall-cmd --list-port  查看端口
firewall-cmd --add-port=xx(端口)/tcp --permanent    如:firewall-cmd --add-port=80/tcp --permanent
加完端口之后要重启防火墙
systemctl reload firewalld.service
再次查看是否能访问nginx服务器
 
 

Nginx安装配置详解的更多相关文章

  1. lvs keepalived 安装配置详解【转】

    lvs keepalived 安装配置详解 张映 发表于 2012-06-20 分类目录: 服务器相关 前段时间看了一篇文章,lvs做负载均衡根F5差不多,说实话不怎么相信,因为F5没玩过,也无法比较 ...

  2. Nginx安装目录详解

    Nginx安装目录详解 1. 查看有关nginx的所有目录列表,输入命令  rpm -ql nginx 可以查看有关nginx目录信息,但是注意 这种命令只能是在基于yum安装的方式才可以. 2. 下 ...

  3. Eclipse IDE for C/C++ Developers安装配置详解

    Eclipse IDE for C/C++ Developers安装配置详解(转) 转自:http://hi.baidu.com/ltb6w/item/986532efd712460f570f1ddc ...

  4. Cloudera CDH 、Impala本地通过Parcel安装配置详解及什么是Parcel

    本文引用自:Cloudera CDH .Impala本地通过Parcel安装配置详解及什么是Parcelhttp://www.aboutyun.com/forum.php?mod=viewthread ...

  5. ubuntu14.04 server ftp 服务安装配置详解

    ubuntu14.04 server ftp 服务安装配置详解 cheungmine 2016-01-27 http://wiki.ubuntu.com.cn/Vsftpd 0 安装好vsftpd服务 ...

  6. JDK10安装配置详解

    JDK10安装配置详解 1. 下载jdk10 1.1 官网下载jdk7的软件包:        地址:http://www.oracle.com/technetwork/java/javase/dow ...

  7. (转)python中调用R语言通过rpy2 进行交互安装配置详解

    python中调用R语言通过rpy2 进行交互安装配置详解(R_USER.R_HOME配置) 2018年11月08日 10:00:11 luqin_ 阅读数:753   python中调用R语言通过r ...

  8. (转)使用LVS实现负载均衡原理及安装配置详解

    使用LVS实现负载均衡原理及安装配置详解 原文:https://www.cnblogs.com/liwei0526vip/p/6370103.html

  9. redis cluster 集群 安装 配置 详解

    redis cluster 集群 安装 配置 详解 张映 发表于 2015-05-01 分类目录: nosql 标签:cluster, redis, 安装, 配置, 集群 Redis 集群是一个提供在 ...

随机推荐

  1. LeetCode——Palindrome Number

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  2. unittest框架(二)单元测试及测试报告

    如果要自测代码,可使用单元测试,需要导入unittest模块,import unittest即可. 例如,自测一个计算连个数相除的函数,代码如下: import unittest def calc(a ...

  3. virtulenv使用

    windows下创建虚拟环境 安装 virtualenv pip3 install virtualenv #选择一个存放虚拟环境的文件夹 cmd中 d: mkdir xxx cd xxx # 创建虚拟 ...

  4. cocos代码研究(26)Widget子类RichView学习笔记

    理论部分 一个显示多个RichElement的容器类. 我们可以使用它很容易显示带图片的文本,继承自 Widget. 代码实践 static RichText * create ()创建一个空的Ric ...

  5. python中的排序

    今天在http://www.pythontip.com刷题的时候遇到一个排序的问题:一个列表中既有字符串,又有数字,该怎么排序. list = [1,2,5,4,'d','s','e',45] lis ...

  6. 字典树 trie

    Trie树        Trie树,就是字母树.Trie树是多叉树,每个节点为一个字母.其根节点为象征节点(就是说没有含义,但是存在这个节点),从根节点开始建立,每个节点至多为26个子节点(不要我说 ...

  7. 2018 Multi-University Training Contest 3 Solution

    A - Problem A. Ascending Rating 题意:给出n个数,给出区间长度m.对于每个区间,初始值的max为0,cnt为0.遇到一个a[i] > ans, 更新ans并且cn ...

  8. facebook graph api 报错SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)')

    使用facebook graph api,报错如下 一开始以为是https证书验证失败,查了一下午源码,没有看到问题,于是把Python27\lib\site-packages\requests\ad ...

  9. Android 自定义View - 饼图

    最近有看到一个自定义等分圆的View,自己尝试做了一个类似的,效果图如下图(1)所示: 图(1) 实现方法:自定义View-ColorCircle,需要的知道的值有圆的半径,等分个数以及扇形颜色. / ...

  10. nmon监控Linux服务器系统资源

    本文转自:http://www.cnblogs.com/hyzhou/archive/2011/12/29/2305860.html 在实际的测试过程中,Loadrunner监控Linux系统资源不太 ...