1 Star 7 Fork 0

zhengquan / Nginx note

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Nginx

学前准备

四项确认
1. 确认系统网络
ping www.baidu.com  
2. 确认yum可用
yum list|grep gcc
3. 确认关闭iptables规则
iptables -F
4. 确认关闭selinux
setenforce 0
5. 安装依赖
yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake 
yum -y install wget httpd-tools vim

Nginx特性

1. IO多路复用epoll
2. 轻量级
3. CPU亲和(affinity)
4. sendfile

Nginx安装

Nginx官网

指定nginx官方提供的yum源
sudo vim /etc/yum.repos.d/nginx.repo

输入一下文本
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

yum list | grep nginx nginx的版本源
ps:这里系统用的是centos6 相关版本请自行修改

yum install nginx

nginx -v 判断是否安装成功
nginx -V 查看所有nginx的模块

Nginx基本参数使用

rpm -ql nginx

/etc/logrotate.d/nginx          Nginx日志轮转。用于logrotate服务日志切割

/etc/nginx                      Nginx主要配置文件
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf

/etc/nginx/fastcgi_params       cgi配置 fastcgi配置
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params

/etc/nginx/koi-utf              Nginx编码转换的映射文件
/etc/nginx/koi-win
/etc/nginx/win-utf

/etc/nginx/mime.types           设置http的Content-Type扩展名对应关系

/etc/sysconfig/nginx            centos7开始用于配置系统守护进程管理方式
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service

/etc/nginx/modules              Nginx模块目录
/usr/lib64/nginx/modules
 
/usr/sbin/nginx                 Nginx服务启动管理的终端命令
/usr/sbin/nginx-debug

/usr/share/doc/nginx-1.12.1     Nginx手册和帮助文档
/usr/share/doc/nginx-1.12.1/COPYRIGHT
/usr/share/man/man8/nginx.8.gz

/var/cache/nginx                Nginx缓存目录

/var/log/nginx                  Nginx日志目录

Nginx安装编译参数

--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib64/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=nginx
--group=nginx
--with-cc-opt=parameters
--with-ld-opt=parameters

Nginx基本配置

nginx.conf

user  nginx;    设置nginx服务的系统使用用户
worker_processes  1;   工作进程数

error_log  /var/log/nginx/error.log warn;  nginx的错误日志
pid        /var/run/nginx.pid;  nginx服务的pid


events {
    worker_connections  1024;  每个工程允许最大连接数
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/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   /usr/share/nginx/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;
    #}
}

补充知识:HTTP

模拟请求命令 curl http://www.imooc.com 返回请求所有信息 curl -v http://www.imooc.com >/dev/null 返回请求头信息

Nginx模块

Nginx http_log_module 日志模块

Nginx sub_status Nginx客户端状态

Nginx random_index_module Nginx随机主页

Nginx sub_module Nginx内容替换

Nginx http_limit_conn_module Nginx连接限制

Nginx http_limit_req_module Nginx请求限制

Nginx http_access_module Nginx Ip认证

Nginx http_auth_basic_module Nginx 用户登陆认证

Nginx http_gzip_static_module. Nginx gzip预读功能

Nginx http_gunzip_module Nginx gunzip的压缩方式

空文件

简介

关于nginx的详细解答以及作业 展开 收起
其他
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
其他
1
https://gitee.com/mslace/Nginx-note.git
git@gitee.com:mslace/Nginx-note.git
mslace
Nginx-note
Nginx note
master

搜索帮助