标签:log sele null sha 推荐 工作模式 错误日志 install 支持
2020年11月4日study
2021年5月12日 review

进入Nginx官网:

把下载好的nginx-1.18.0.tar.gz放到/usr/local/software/server下(为了便于管理,下载的软件建议放到/usr/local/下面)
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
tar -zxvf nginx-1.18.0.tar.gz
./configure
make
make install
默认安装路径为:/usr/local/nginx
# sbin 放的是二进制文件
cd /usr/local/nginx/sbin
# 启动 nginx
./nginx
查看nginx进程:ps -ef | grep "nginx"
删除进程:kill -9 进程id
阿里云网络安全组配置80端口,防火墙开放端口:



/usr/local/nginx
- conf                    # 所有配置文件目录
- - - nginx.conf          # 默认的配置文件
- - - nginx.conf.default  # 默认模板
- html                    # 编译安装时 nginx 的默认站点目录
- - - 50x.html            # 错误页面
- - - index.html          # 默认首页
- logs                    # nginx 默认的日志路径,包括错误日志及访问日志
- - - access.log          # nginx 访问日志
- - - error.log           # 错误日志
- - - nginx.pid           # nginx 启动后的进程 id
- sbin                    # nginx命令的目录
- - - nginx               # 启动命令
# 默认配置文件启动
./nginx 
# 重启,加载默认配置文件
./nginx -s reload 
# 启动指定某个配置文件
./nginx -c /usr/local/nginx/conf/nginx.conf
# 停止
./nginx -s stop 
# 关闭进程,nginx 有 master process 和 worker process,先关闭 master process
ps -ef | grep "nginx"
kill -9 PID
# 每个配置项由配置指令和指令参数两个部分构成
# 指定 Nginx Worker 进程运行以及用户组
# user  nobody;
# 推荐和 CPU 的核数保持一致
# 例如:前端发起请求到后端是由 worker 进行处理,并不是越多越好,如果超过了 CPU 核数,则要进行切换,消耗性能。
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;
# 事件模块指令,用来指定 Nginx 的 IO 模型,Nginx 支持的有 select、poll、kqueue、epoll 等。
# 不同的是 epoll 用在 Linux 平台上,而 kqueue 用在 BSD 系统中,对于 Linux 系统,epoll 工作模式是首选。
events {
    # 异步非阻塞,提升 IO 性能
    use epoll;
    # 定义 Nginx 每个进程的最大连接数,作为服务器来说:worker_connections * worker_processes;
    # 作为反向代理来说,最大并发数量应该是 worker_connections * worker_processes/2。
    # 因为反向代理服务器,每个并发会建立与客户端的连接和与后端服务的连接,会占用两个连接。
    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; # main 就是上面的模板名称
    # 是否开启高效传输模式 on 开启 off 关闭
    sendfile        on;
    
    # 减少网络报文段的数量
    #tcp_nopush     on;
    # 客户端连接保持活动的超时时间,超过这个时间之后,服务器会关闭该连接
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    # 虚拟主机的配置
    server {
        # 虚拟主机的服务端口
        listen       80;
        # 用来指定 IP 地址或域名,多个域名之间用空格分开
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        # URL 地址匹配(除了前面的域名之外,就是具体的路径)
        location / {
            # 服务默认启动目录(root 指的的存储路径;html 即 /usr/local/nginx/html,相对路径)
            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;
        #}
    }
    # 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;
    #    }
    #}
}
标签:log sele null sha 推荐 工作模式 错误日志 install 支持
原文地址:https://www.cnblogs.com/ddhhdd/p/14759820.html