1.到nginx官网下载源码包。最好下载稳定版本,nginx官网http://www.nginx.org/

2.安装nginx依赖包运行命令:

sudo apt-get install libssl-dev
sudo apt-get install libpcre3 libpcre3-dev

3.解压下载的nginx源码包。检查编译环境 ./configure --prefix=/usr/local/nginx

4.编译安装 make && make install

5.到nginx安装目录执行启动命令:/usr/local/nginx/sbin/nginx

关闭命令:/usr/local/sbin/nginx -s stop (停止)
重启命令:/usr/local/sbin/nginx -s reload (重启)

启动之后浏览器中http://localhost/查看是否成功。

6.nginx配置文件所在目录/usr/local/nginx/conf/nginx.conf

配置文件详解如下:

#运行用户 
#user  nobody;
#启动进程 
worker_processes  1;

#全局错误日志及PID文件 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#工作模式及连接数上限 
events {
    use epoll; 
       worker_connections  1024;
}

#设定http服务器,利用它的反向代理功能提供负载均衡支持 
http {
    #设定mime类型 
    include       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  logs/access.log  main;

sendfile        on;
        #tcp_nopush     on;

#keepalive_timeout  0;
        #客户端和nginx之间空闲链接超时时间
        keepalive_timeout  120;

#设定负载均衡的服务器列表
    upstream mysvr {
        #weigth参数表示权值,权值越高被分配到的几率越大
        #本机上的Squid开启3128端口
        server 127.0.0.1:8080 weight=1;
        #server 119.254.82.237:8080  weight=1;
    } 
    #是否开启gzip模块 
    #gzip  on;
    #gzip_min_length  1100;
    #gzip_buffers    4 8k;
    #gzip_types      text/plain; 
    #设定虚拟主机 
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #设定本虚拟主机的访问日志 
        #access_log  logs/host.access.log  main;
        #location / {
        #    root   html;
        #    index  index.html index.htm;
               # }
        #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;
        }

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #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;
        #}

# deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}

#对 "/" 启用负载均衡
        location / {
            proxy_pass      http://mysvr;
            proxy_redirect          off;
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            #客户端body中最大数据量
            client_max_body_size    10m;
            client_body_buffer_size 128k;
            # 链接到主机超时时间
            proxy_connect_timeout  90;
            # 向主机发送数据超时时间
            proxy_send_timeout      90;
            # 从主机读取数据超时时间
            proxy_read_timeout      90;
            proxy_buffer_size      4k;
            proxy_buffers          4 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;
        } 
    }
    # 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;
    #    }
    #}
}

ubuntu nginx 安装以及配置文件详解的更多相关文章

  1. nginx安装及配置文件详解

    一)nginx安装及模块讲解 1.1.nginx安装步骤 mkdir /soft wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxf ...

  2. Nginx安装及配置详解【转】

    nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...

  3. [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html

    Nginx安装及配置详解   nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...

  4. Linux中Nginx安装与配置详解

    转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...

  5. 【转】nginx服务器安装及配置文件详解

    原文:http://seanlook.com/2015/05/17/nginx-install-and-config/ nginx服务器安装及配置文件详解 nginx在工作中已经有好几个环境在使用了, ...

  6. [转帖]nginx服务器安装及配置文件详解

    nginx服务器安装及配置文件详解 http://seanlook.com/2015/05/17/nginx-install-and-config/  发表于 2015-05-17 |  更新于: 2 ...

  7. Ubuntu下安装JDK图文详解

    很详细的在Ubuntu中安装JDK图文详解教程,我们选择的是jdk1.6.0_30版本.安装文件名为jdk-6u30-linux-i586.bin. 1.复制jdk到安装目录 (1)假设jdk安装文件 ...

  8. nginx官方源安装-主配置文件详解

    HTTP相关术语 PV : Page Visit 页面独立浏览量,查看日志生成条数可以看到PV数量. PV全称Page View,中文翻译即页面浏览.其具体的度量方法是从浏览器发出一个对网络服务器的请 ...

  9. haproxy 安装与配置文件详解

    本文主要阐述haproxy的安装配置详解,对于它的概念,作用,功能,和其它LB软件的区别,优点,缺点等不再进行说明. 一. haproxy 的安装配置 # cat /etc/redhat-releas ...

随机推荐

  1. HTML5+JS 《五子飞》游戏实现(三)页面和棋盘棋子

    前面两节,我们已经对<五子飞>有个初步的认识,对走棋路线也有了基本的了解,现在里沃特继续跟大家分享HTML页面,另外把棋盘棋子也画出来. 演示地址:http://www.lyout.com ...

  2. 在VS2010 下编译 cocos2d-x-2.1.4

    首先感谢 cocos2d-x 团队为我们做出这么好的跨平台框架,让我们这些码农省了很多时间,事半功倍. 里沃特最近在编译 win32 版本的时候最到一点小问题,现在记录下,说不定能帮到某些初学的朋友. ...

  3. Ext.Net-Grid 篇

    概述 前两篇分别介绍了Ext.NET-基础 和 Ext.NET-布局,从本篇开始我们尽量做一些实际工作中用到的例子. 在Ext.NET官方示例中,关于GridPanel的例子是最多的(近百个),篇幅所 ...

  4. Bootstrap系列 -- 10. 网格布局

    一. 实现原理 网格布局是通过容器的大小,平均分为12份(可以修改),再调整内外边距,和表格布局有点类似但是也存在区别. 实现步骤如下: (1) 数据行.row 必须包含在容器.container 中 ...

  5. P值与significant(显著性)的理解

    P值与significant的理解 来源:广州市统计局   发表日期:2015-01-21     P值可以理解为结论的风险大小,也就是根据数据得出的结果有多大的错误风险,P值越小,结论错误的风险越小 ...

  6. zabbix解决中文乱码问题(没有测试成功)

    zabbix解决中文乱码问题 1.在windows系统中找一个自己喜欢的字体,这里我们用:msyh.ttf 2.将字体上传至/var/www/html/zabbix/fonts目录下 [root@za ...

  7. PHP ElasticSearch的使用

    系统是Windows server 2003. ElasticSearch是一个基于Lucene的稳定的.分布式.RESTFul的搜索引擎.其实所谓的RestFul就是它提供URL供你调用(建立索引和 ...

  8. 【BZOJ 2154】Crash的数字表格

    制杖了,,,求前缀和的时候$i×i$是int,然后当$i=10^7$时就喜闻乐见地爆int了,,,对拍之后查了一个下午的错才发现这个问题,,,最后枚举用的变量全都强行加上long long才A掉 #i ...

  9. WEB界面onload前的加载流程❤❤

    开始的流程: 1.先发请求给DNS进行域名解析获取服务器IP 2.向步骤1获取的服务器IP发送HTTP请求 //服务器的内部处理 3.服务器接收请求后,解析主机头对应的站点,把请求传送给站点 //返回 ...

  10. spoj687 后缀数组重复次数最多的连续重复子串

    REPEATS - Repeats no tags  A string s is called an (k,l)-repeat if s is obtained by concatenating k& ...