Nginx 安装&默认配置简介

 

一.  yum 安装

二. mac 安装

三. Linux编译安装

1.下载

2.安装先安装nginx依赖的包

gc

PCRE

zlib

openssl

3.上传nginx到linux

4. 解压拷贝

5.安装

进入nginx的目录

创建nginx的安装目录

运行configure

make编译

make install编译安装

6. Nginx的目录说明

7. Nginx的​启动、停止

启动

停止

刷新[当用户修改了conf/nginx.conf]

四. 默认配置说明


 

一.  yum 安装

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install -y nginx

配置文件目录:

/etc/nginx/conf.d

二. mac 安装

查看: brew search nginx

安装: brew install nginx

nginx安装路径
/usr/local/Cellar/nginx/1.6.2

发布页面:
/usr/local/var/www 
配置文件:
/usr/local/etc/nginx/nginx.conf 

日志路径:
/usr/local/var/log/nginx/error.log

三. Linux编译安装

1.下载

http://nginx.org/en/download.html

 

 

 

2.安装先安装nginx依赖的包


gc

      安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc

yum install gcc-c++

PCRE

   PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

yum install -y pcre pcre-devel

zlib

zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

yum install -y zlib zlib-devel

openssl

      OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。 
      nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

yum install -y openssl openssl-devel

3.上传nginx到linux

 

4. 解压拷贝

#把解压nginx-1.16.1.tar.gz包

tar -zxvf nginx-1.16.1.tar.gz

#修改文件夹的名字

mv nginx-1.16.1 nginx

#把nginx拷贝到/usr/local/src里面

cp -r nginx /usr/local/src

 

5.安装

进入nginx的目录

cd /usr/local/src/nginx

 

创建nginx的安装目录

mkdir  /usr/nginx

 

运行configure

./configure --prefix=/usr/nginx    (指定安装目录编译)

make编译

cd /usr/local/src/nginx

make

make install编译安装

cd /usr/local/src/nginx

make  install

 

6. Nginx的目录说明

conf 配置目录 

html静态文件[cdn加速]

logs日志目录

sbin执行文件

 

7. Nginx的​启动、停止

启动

cd /usr/nginx/sbin

./nginx  

停止

nginx -s stop

刷新[当用户修改了conf/nginx.conf]

./nginx -s reload

 

四. 默认配置说明

 


#代表权限
#user  nobody;  

#工作进程
worker_processes  1;

#日志
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

#网络请求
http {
    #支持的文件类型
    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;
    keepalive_timeout  65;

    #gzip  on;

    #代表服务配置
    server {
        listen       80; #端口配置
        server_name  localhost;   #服务名称

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #当用户访问 http://ip:80/
        location / {
            root   html;  #当匹配当"/"这个规则时指向 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;
        # 当服务出现 500 错误时 定向位置
        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;
        #}
    }


    # 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;
    #    }
    #}

}

 

 

发布了304 篇原创文章 · 获赞 797 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/zhanglong_4444/article/details/104275257