Nginx日常操作和配置
安装位置:/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;
# }
#} }
Nginx日常操作和配置的更多相关文章
- linux下nginx日常操作
一.检查配置文件语法 [root@node2 /]# nginx -tc /usr/local/nginx/conf/nginx.conf nginx: the configuration file ...
- apace日常操作和配置
[root@limt modules]# /usr/sbin/apachectl -h Usage: /usr/sbin/httpd [-D name] [-d directory] [-f file ...
- Nginx日常维护操作(3)
一.简明nginx常用命令 1. 启动 Nginx /sbin/nginx service nginx start 2. 停止 Nginx /sbin/nginx -s stop /sbi ...
- nginx日常维护常用命令
http://www.jb51.net/article/47750.htm 一.简明nginx常用命令 1. 启动 Nginx poechant@ubuntu:sudo ./sbin/nginx 2. ...
- 2.Nginx日常维护技巧
Nginx日常维护技巧 Nginx配置正确性检查 nginx提供了配置文件调试功能,可以快速定义配置文件存在的问题.执行如下命令检测配置文件的正确性: [root@localhost 桌面]# whi ...
- Nginx简单操作
Nginx简单操作 平滑重启:读取配置文件,正确后启动新nginx,关闭旧服务进程 # kill HUP nginx.pid # /usr/sbin/nginx -c /etc/nginx/nginx ...
- nginx四层负载均衡配置
nginx四层负载均衡配置代理Mysql集群 环境如下: ip 192.168.6.203 Nginx ip 192.168.6.*(多台) Mysql 步骤一 查看Nginx是否安装stream模块 ...
- ORACLE日常操作手册
转发自:http://blog.csdn.net/lichangzai/article/details/7955766 以前为开发人员编写的oracle基础操作手册,都基本的oracle操作和SQL语 ...
- nginx安装升级及配置详解
1.简介 2.安装配置 3.配置文件介绍 4.启动.停止.平滑重启.升级 一.Nginx简介 Nginx(engine x)是俄罗斯人Igor Sysoev编写的一款高性能的http和反向代理服务器. ...
随机推荐
- C++项目中的extern "C" {}
from:http://www.cnblogs.com/skynet/archive/2010/07/10/1774964.html C++项目中的extern "C" {} 20 ...
- JavaScript URL编码转换函数 encodeURIComponent()
encodeURIComponent()定义和用法 encodeURIComponent() 函数可把字符串作为 URI 组件进行编码. 语法:encodeURIComponent(URIstring ...
- $_SERVER["SCRIPT_NAME"]、$_SERVER["PHP_SELF"]、$_SERVER["QUERY_STRING"]、$_SERVER["REQUEST_URI"]
1.$_SERVER["SCRIPT_NAME"] 说明:包含当前脚本的路径 2.$_SERVER["PHP_SELF"] 说明:当前正在执行脚本的文件名 3. ...
- make 和 makefile 的关系
程序的 编译 和 链接 要先总结 make 和 makefile,就需要先了解下面这个过程: 预编译:也叫预处理,进行一些文本替换工作,比如将 #define 定义的内容,在代码中进行替换: 编译:将 ...
- Unix/Linux进程间通信(二):匿名管道、有名管道 pipe()、mkfifo()
1. 管道概述及相关API应用 1.1 管道相关的关键概念 管道是Linux支持的最初Unix IPC形式之一,具有以下特点: 管道是半双工的,数据只能向一个方向流动:需要双方通信时,需要建立起两个管 ...
- MySQL Cluster在线添加数据节点
增加或减少数据节点的数量和 NoOfReplicas(即副本数,通过管理节点的config.ini配置文件来设置)有关,一般来说NoOfReplicas是2,那么增加或减少的数量也应该是成对的,否则要 ...
- mongo副本集搭建及服务器复用方案
比较常见的mongodb副本集搭建是有:常规节点.数据副本.仲裁节点组成,也就是需要三台服务器组建.常规节点即数据的主存储节点,数据副本是主存储节点的从属节点,它定期去主节点获取更新日志来更新自己.仲 ...
- Hydra用户手册
Hydra 参数: -R继续从上一次进度接着破解 -S大写,采用SSL链接 -s <PORT>小写,可通过这个参数指定非默认端口 -l <LOGIN>指定破解的用户,对特定用户 ...
- php 批量去空格和注释
原理:php自带函数去注释和空格 => php_strip_whitespace如题,新建文件 re_note.php,将文件放入你要批量去除注释和空格的根目录.然后运行就行了 代码如下: & ...
- JavaScript刷新页面n种方法
window.location.href 属性 window.location.href=window.location.href;//刷新当前页面 asp.net 或 asp 利用此功能刷新页面 R ...