(Three) nginx commonly used commands and configuration files

(1) Common commands

(1) Installation

The premise is that brew is installed

brew install nginx

(2) View the nginx version

nginx -v

(3) Start nginx

sudo nginx

(4) Stop nginx

nginx -s stop

(5) Restart nginx

nginx -s reload

(Two) configuration file

The directory path of the installed nginx is as follows:

/usr/local/etc/nginx

There are so many files below, the configuration file is nginx.conf

#user  nobody;
#nginx进程,一般数值为cpu核数,worker_processes值越大,说明可以支持的并发请求也就越多
worker_processes  1;
#错误日志存放目录
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#进程pid存放位置
#pid        logs/nginx.pid;

#工作模式及连接数上限
events {
    #单个后台worker process进程的最大并发链接数
    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"';
    #nginx访问日志
    #access_log  logs/access.log  main;
    #开启高效传输模式   
    sendfile        on;
    #激活tcp_nopush参数可以允许把httpresponse header和文件的开始放在一个文件里发布, 积极的作用是减少网络报文段的数量
    #tcp_nopush     on;
    #连接超时时间,单位是秒
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #开启gzip压缩功能
    #gzip  on;
    
    #基于域名的虚拟主机
    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;
        # 将服务器错误页面重定向到静态页面/50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }        

       
        #代理PHP脚本到Apache上监听127.0.0.1:80
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

   
        #将PHP脚本传递到正在监听127.0.0.1:9000的FastCGI服务器
        #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;
        #}

        #如果Apache的文档根目录与nginx的根目录一致,则拒绝访问.htaccess文件
        #location ~ /\.ht {
        #    deny  all;
        #}
    }



    #另一个虚拟主机,混合使用IP、名称和基于端口的配置
    #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;
    #    服务端key
    #    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;
    #    }
    #}
}

The configuration file is divided into three modules:
(1) Global block: configuration instructions that mainly affect the overall operation of the nginx server

(2) event block: mainly affects the link between the Nginx server and the user network

(3) http block: load balancing, reverse proxy, dynamic and static separation are all set in this module

http block contains http block and server block

Guess you like

Origin blog.csdn.net/Luckyzhoufangbing/article/details/108772989