首页 > 代码库 > Nginx学习笔记02Nginx启动运行与命令行
Nginx学习笔记02Nginx启动运行与命令行
1.1. Nginx启动运行
Nginx的配置文件的一个简单的例子。
conf目录下的nginx.cfg文件的内容如下:
#worker进程个数。
worker_processes 1;
#事件模块。
events {
worker_connections 1024;
}
#http模块。
http {
include mime.types;
default_type application/octet-stream;
#在8000端口监听。
server {
listen 8000;
server_name localhost;
#根路径下首页为本地html目录下的index.html文件。
location / {
root html;
index index.html;
}
}
}
可以启动nginx服务器。
[d@192.168.197.101:/opt/nginx/sbin]$./nginx&
[1] 69581
[d@192.168.197.101:/opt/nginx/sbin]$ps -elf|grep nginx
1 S d 69582 1 0 80 0 - 4028 sigsus 22:54 ? 00:00:00 nginx: master process ./nginx
1 S d 69583 69582 0 80 0 - 4134 ep_pol 22:54 ? 00:00:00 nginx: worker process
0 S d 69585 69531 0 80 0 - 4157 pipe_w 22:54 pts/0 00:00:00 grep --color=auto nginx
在浏览器中访问网站:
至此,一个最简单的Nginx服务器搭建成功。Nginx强大的功能所能实现的远远不止一个静态的网站这么简单,后续博客将继续探索Nginx的世界。
1.2. Nginx命令行
nginx程序提供了简洁而有用的命令行接口。
[d@192.168.197.101:/opt/nginx/sbin]$./nginx -h
nginx version: nginx/1.11.8
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
[d@192.168.197.101:/opt/nginx/sbin]$./nginx -V
nginx version: nginx/1.11.8
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configure arguments: --prefix=/opt/nginx
-t : test configuration and exit
[d@192.168.197.101:/opt/nginx/sbin]$./nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
stop:强制退出服务。
quit:优雅的退出服务,退出前处理完当前所有请求。
reopen:重新打开日志文件。
reload:重新加载配置文件。
[d@192.168.197.101:/opt/nginx/sbin]$./nginx -s reload
[d@192.168.197.101:/opt/nginx/sbin]$ps -elf|grep nginx
1 S d 69582 1 0 80 0 - 4028 sigsus 22:54 ? 00:00:00 nginx: master process ./nginx
1 S d 69588 69582 0 80 0 - 4135 ep_pol 23:04 ? 00:00:00 nginx: worker process
0 S d 69590 69531 0 80 0 - 4157 pipe_w 23:04 pts/0 00:00:00 grep --color=auto nginx
[d@192.168.197.101:/opt/nginx/sbin]$./nginx -s stop
[d@192.168.197.101:/opt/nginx/sbin]$ps -elf|grep nginx
0 S d 69593 69531 0 80 0 - 4157 pipe_w 23:05 pts/0 00:00:00 grep --color=auto nginx
-p prefix : set prefix path (default: /opt/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
Nginx学习笔记02Nginx启动运行与命令行