nginx学习2:nginx常用命令和配置文件

nginx学习2:nginx常用命令和配置文件

nginx常用命令

 nginx常用命令在命令/usr/local/nginx/sbin/目录下执行
 
[root@VM_0_4_centos sbin]# cd /usr/local/nginx/sbin/
[root@VM_0_4_centos sbin]# ls
nginx

  1-查看版本号:./nginx -v

[root@VM_0_4_centos sbin]# ./nginx -v
nginx version: nginx/1.12.2
 

  2-启动nginx:./nginx 

启动前
[root@VM_0_4_centos sbin]# ps -ef | grep nginx
root      5130  2699  0 21:24 pts/1    00:00:00 grep --color=auto nginx
启动指令
[root@VM_0_4_centos sbin]# ./nginx 
启动后
[root@VM_0_4_centos sbin]# ps -ef | grep nginx
root      5651     1  0 21:27 ?        00:00:00 nginx: master process ./nginx
nobody    5652  5651  0 21:27 ?        00:00:00 nginx: worker process
root      5663  2699  0 21:27 pts/1    00:00:00 grep --color=auto nginx

  3-关闭nginx:./nginx -s stop

关闭前
[root@VM_0_4_centos sbin]# ps -ef | grep nginx
root      5085  2699  0 21:24 pts/1    00:00:00 grep --color=auto nginx
root     16148     1  0 16:24 ?        00:00:00 nginx: master process ./nginx
nobody   16149 16148  0 16:24 ?        00:00:00 nginx: worker process
关闭指令
[root@VM_0_4_centos sbin]# ./nginx -s stop
关闭后
[root@VM_0_4_centos sbin]# ps -ef | grep nginx
root      5130  2699  0 21:24 pts/1    00:00:00 grep --color=auto nginx

  4-重新加载:./nginx -s reload

[root@VM_0_4_centos sbin]# ./nginx -s reload

nginx配置文件

配置文件位置:/usr/local/nginx/conf/nginx.conf

[root@VM_0_4_centos conf]# cd /usr/local/nginx/conf/
[root@VM_0_4_centos conf]# ls -al
total 68
drwxr-xr-x  2 root root 4096 Jan 29 16:24 .
drwxr-xr-x 11 root root 4096 Jan 29 16:14 ..
-rw-r--r--  1 root root 1077 Jan 29 15:50 fastcgi.conf
-rw-r--r--  1 root root 1077 Jan 29 15:50 fastcgi.conf.default
-rw-r--r--  1 root root 1007 Jan 29 15:50 fastcgi_params
-rw-r--r--  1 root root 1007 Jan 29 15:50 fastcgi_params.default
-rw-r--r--  1 root root 2837 Jan 29 15:50 koi-utf
-rw-r--r--  1 root root 2223 Jan 29 15:50 koi-win
-rw-r--r--  1 root root 3957 Jan 29 15:50 mime.types
-rw-r--r--  1 root root 3957 Jan 29 15:50 mime.types.default
-rw-r--r--  1 root root 2658 Jan 29 16:24 nginx.conf
-rw-r--r--  1 root root 2656 Jan 29 15:50 nginx.conf.default
-rw-r--r--  1 root root  636 Jan 29 15:50 scgi_params
-rw-r--r--  1 root root  636 Jan 29 15:50 scgi_params.default
-rw-r--r--  1 root root  664 Jan 29 15:50 uwsgi_params
-rw-r--r--  1 root root  664 Jan 29 15:50 uwsgi_params.default
-rw-r--r--  1 root root 3610 Jan 29 15:50 win-utf

 配置文件概述

#user  nobody;

##全局块
##
这是 Nginx 服务器并发处理服务的关键配置,worker_processes 值越大,可以支持的并发处理量也越多,但是会受到硬件、软件等设备的制约
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 块
events {
  ##示每个 work process 支持的最大连接数为 1024 worker_connections
1024; } ##http块 http {
   ##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;
   ##http server 块 server { listen
8081; 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; # 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; # } #} }

 配置文件分为三部分

  1-全局块:从配置文件开始到 events 块之间的内容,主要会设置一些影响 nginx 服务器整体运行的配置指令,主要包括配置运行 Nginx 服务器的用户(组)、允许生成的 worker process 数,进程 PID 存放路径、日志存放路径和类型以及配置文件的引入等

  2-events块:events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括是否开启对多 work process 下的网络连接进行序列化,是否允许同时接收多个网络连接,选取哪种事件驱动模型来处理连接请求,每个 word process 可以同时支持的最大连接数等。

  3-http块:算是 Nginx 服务器配置中最频繁的部分,代理、缓存和日志定义等绝大多数功能和第三方模块的配置都在这里。需要注意的是:http 块也可以包括 http 全局块、server 块。

    • http 全局块:http 全局块配置的指令包括文件引入、MIME-TYPE 定义、日志自定义、连接超时时间、单链接请求数上限等。
    • server块:这块和虚拟主机有密切关系,虚拟主机从用户角度看,和一台独立的硬件主机是完全省互联网服务器硬件成本。每个 http 块可以包括多个 server 块,而每个 server 块就相当于一个虚拟主机。而每个 server 块也分为全局 server 块,以及可以同时包含多个 locaton 块。      
原文地址:https://www.cnblogs.com/wobuchifanqie/p/12241523.html