NGINX学习笔记

NGINX安装位置

[root@localhost /]# which nginx
/usr/sbin/nginx

执行NGINX

[root@localhost sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

测试启动

[root@localhost sbin]# ps -ef | grep nginx
root      7645     1  0 10:51 ?        00:00:00 nginx: master process ./usr/sbin/nginx
nginx     7646  7645  0 10:51 ?        00:00:00 nginx: worker process
nginx     7647  7645  0 10:51 ?        00:00:00 nginx: worker process
nginx     7648  7645  0 10:51 ?        00:00:00 nginx: worker process
nginx     7649  7645  0 10:51 ?        00:00:00 nginx: worker process
root     10857 16807  0 10:53 pts/0    00:00:00 grep --color=auto nginx

关闭NGINX

​
[root@localhost sbin]# nginx -s stop #关闭nginx
[root@localhost sbin]# nginx -s quit #安全退出 nginx
[root@localhost sbin]# nginx -s reload #重新加载 nginx
[root@localhost sbin]# nginx -s reopen #重新开启 nginx

​

Nginx配置文件位置

[root@localhost /]# find -name "nginx.conf"
./etc/nginx/nginx.conf

Nginx配置文件详解

[root@localhost /]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
配置的详细信息,请参阅:
#*官方英文文档:http://nginx.org/en/docs/
#*俄罗斯官方文件:http://nginx.org/ru/docs/

user nginx; #nginx的启动用户
worker_processes auto; #开启进程数 <=CPU数 auto是自动配置
error_log /var/log/nginx/error.log; #错误日志保存位置
pid /run/nginx.pid; #指定nginx进程运行文件存放地址

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

#每个进程最大连接数(最大连接=连接数x进程数)每个worker允许同时产生多少个链接,默认1024
events {
    worker_connections 1024;
}

http {
    client_max_body_size 30m; #客户端请求服务器最大允许大小,在“Content-Length”请求头中指定。如果请求的正文数据大于client_max_body_size,HTTP协议会报错 413 Request Entity Too Large。如果需要上传大文件,一定要修改该值。

    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; #请求日志保存位置 combined为日志格式的默认值

     #打开发送文件
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;  #连接超时时间
    types_hash_max_size 4096; #影响散列表的冲突率。types_hash_max_size越大,就会消耗更多的内存,但散列key的冲突率会降低,检索速度就更快。types_hash_max_size越小,消耗的内存就越小,但散列key的冲突率可能上升。
默认为1024

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;


# Settings for a TLS enabled server. #配置虚拟主机,基于域名、ip和端口

#    server {
#        listen       443 ssl http2; #监听端口
#        listen       [::]:443 ssl http2; #监听域名
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt"; # 证书路径
#        ssl_certificate_key "/etc/pki/nginx/private/server.key"; # 证书密钥路径
#        ssl_session_cache shared:SSL:1m; # ssl session cache分配1m空间, 缓存ssl session
#        ssl_session_timeout  10m; # ssl session 超时时间为10m
#        ssl_ciphers HIGH:!aNULL:!MD5; #指出允许的密码,密码指定为OpenSSL支持的格式
#        ssl_prefer_server_ciphers on; #该指令指定是否服务器密码优先客户端密码


#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }

         #错误页面及其返回地址            
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值