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. mysql 数据操作 单表查询 练习

    查出所有员工的名字,薪资,格式为 <名字:egon>,<薪资:3000> mysql> select concat('<姓名:',name,'>') as n ...

  2. js-template-art【三】js api

    一.js api使用 1.template(filename, data) 根据模板名渲染模板. var html = template('tplScriptId', { value: 'aui' } ...

  3. java反射获得泛型参数getGenericSuperclass():获取到父类泛型的类型

    public class Person<T> { } import java.lang.reflect.ParameterizedType; import java.lang.reflec ...

  4. CentOS7.5基础优化与常用配置

    目录 最小化全新安装CentOS7基础优化 配置yum源 安装常用软件 关闭防火墙 关闭SELinux 优化ulimit 历史命令记录改为1万条 把命令提示符改为绿色 添加vim配置文件 添加一个普通 ...

  5. Debian更新软件源提示There is no public key available for the following key IDs的解决方法

    今天装了的debian7.0 但是更新软件源的时候出错 提示 W: There is no public key available for the following key IDs: 9D6D8F ...

  6. (16)Cocos2d-x 多分辨率适配完全解析

    Overview 从Cocos2d-x 2.0.4开始,Cocos2d-x提出了自己的多分辨率支持方案,废弃了之前的retina相关设置接口,提出了design resolution概念. 3.0中有 ...

  7. Xcel 测试版使用手册

    基于无任何文笔可言,所以直接上使用方法吧. 1.引用dll,如何引用dll请谷歌. 2.使用 //实例化对象 LT.XMLExcel.XlsxOption xOption = new LT.XMLEx ...

  8. hdu1199 线段树

    这题说的是给了 n 个操作. 每个操作会把 [a,b] 之间的球 涂为黑色或者 白色, 然后最后问 最长的连续的白色的 球有多少个,初始的时候全是黑的. 我们将所有的点离散化, 记得离散 a-1, b ...

  9. 一篇关于Redis的很不错的文章,转载保存下

    绝大部分写业务的程序员,在实际开发中使用 Redis 的时候,只会 Set Value 和 Get Value 两个操作,对 Redis 整体缺乏一个认知.这里对 Redis 常见问题做一个总结,解决 ...

  10. SQL Server System.Data.SqlClient.SqlException:已成功于服务器建立连接,但是在 登录前的握手期间发生错误

    一.错误描述 错误名称如上.整体错误如下: System.Data.EntityException 基础提供程序在Open上失败--> System.Data.SqlClient.SqlExce ...