安装位置:/usr/local/nginx
配置目录:/usr/local/nginx/conf
配置文件:/usr/local/nginx/conf/nginx.conf
启动命令:/usr/local/nginx/sbin/nginx

[root@limt sbin]# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.7.9
Usage: nginx [-?hvVtq] [-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
-t : test configuration and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
1 指定配置文件启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-c参数指定了要加载的nginx配置文件路径 [root@limt sbin]# ps -ef|grep nginx
root 4631 1 0 03:17 ? 00:00:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf
nobody 4632 4631 0 03:17 ? 00:00:00 nginx: worker process
root 4634 4496 0 03:18 pts/0 00:00:00 grep nginx 2 修改配置文件后重新加载
kill -HUP 主进称号或进程号文件路径(/usr/local/nginx/logs/nginx.pid)
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
或者使用
/usr/nginx/sbin/nginx -s reload 3 测试配置文件正确性
[root@limt sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 4 停止nginx
从容停止Nginx:
kill -QUIT 主进程号
快速停止Nginx:
kill -TERM 主进程号
强制停止Nginx:
pkill -9 主进程号

基本配置:/usr/local/nginx/conf/nginx.conf

#指定nginx worker进程运行用户以及用户组,默认nobody
user nobody;
#指定nginx要开启的进程数。最好与CPU个数相同
worker_processes 2; #用来定义全局错误日志文件。级别有:debug、info、notice、warn、error和crit。debug输出日志最为详细,criti输出日志最少
#error_log logs/error.log;
error_log logs/error.log notice;
#error_log logs/error.log info; #用来指定进程id的存储文件位置
pid logs/nginx.pid; #设定nginx的工作模式及连接上限
events {
#支持的工作模式有:select、poll、kqueue、epoll和rtsig.对于linux系统,epoll是首选模式
use epoll;
#定义nginx每个进程的最大连接数
worker_connections 2048;
} #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阻塞
#tcp_nopush on; #用于设置客户端连接保持活动的超时时间,超过这个时间,服务器会关闭该连接
#keepalive_timeout 0;
keepalive_timeout 65; #支持压缩传输,提高传输速度
#gzip on; #虚拟主机
server {
#监听端口
listen 80;
#主机头(域名)
server_name localhost; #web服务器的语言编码
#charset koi8-r; access_log logs/host.access.log main; #匹配url地址中有"/",则执行花括号中的配置
location / {
#虚拟主机的本地目录,完整路径:/opt/nginx/html,也可写绝对路径
root /var/nginx;
#默认索引的首页格式及顺序
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. 给 C# 开发者的代码审查清单
  2. Git Windows客户端保存用户名与密码
  3. 一直都在说反射很有用 谈谈大型.NET ERP系统有哪些地方用到了反射
  4. iOS开发UI篇—transframe属性(形变)
  5. VS2010链接TFS
  6. Java字符流读写数据的两种方式
  7. Java 设计模式_复合模式(2016-08-31)
  8. iOS开发之UIApplication
  9. shell之路【第二篇】运算与文件调用
  10. linux下python+pycharm安装
  11. DSAPI 简单WebAPI实现
  12. iOS 传感器集锦
  13. Spring学习14-源码下载地址
  14. centos7下haproxy1.7的使用与配置
  15. Proxy 动态代理 InvocationHandler CGLIB MD
  16. 前端常用功能记录(二)—datatables表格(转)
  17. 关于Unity中Cg的基本语法和使用
  18. win7下android开发环境搭建(win7 64位)
  19. VBA 语言基础
  20. h5 和之前版本的区别

热门文章

  1. Unity3D游戏在iOS上因为trampolines闪退的原因与解决办法
  2. log4net各种Filter使用【转】
  3. git学习之旅
  4. Node.js Stream - 实战篇
  5. cf723d Lakes in Berland
  6. [Linux & SVN] SVN介绍及Linux下SVN命令收录
  7. PropertiesFactoryBean PropertyPlaceholderConfigurer 区别
  8. PHP mysql与mysqli事务详解
  9. js中apply()和call()方法的使用
  10. Python里*arg 和**kwargs的作用