首页 > 代码库 > Nginx日常操作和配置
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 -hnginx version: nginx/1.7.9Usage: 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 file1 指定配置文件启动/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf-c参数指定了要加载的nginx配置文件路径[root@limt sbin]# ps -ef|grep nginxroot 4631 1 0 03:17 ? 00:00:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.confnobody 4632 4631 0 03:17 ? 00:00:00 nginx: worker process root 4634 4496 0 03:18 pts/0 00:00:00 grep nginx2 修改配置文件后重新加载kill -HUP 主进称号或进程号文件路径(/usr/local/nginx/logs/nginx.pid)kill -HUP `cat /usr/local/nginx/logs/nginx.pid`或者使用/usr/nginx/sbin/nginx -s reload3 测试配置文件正确性[root@limt sbin]# ./nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful4 停止nginx从容停止Nginx:kill -QUIT 主进程号快速停止Nginx:kill -TERM 主进程号强制停止Nginx:pkill -9 主进程号
基本配置:/usr/local/nginx/conf/nginx.conf
#指定nginx worker进程运行用户以及用户组,默认nobodyuser 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日常操作和配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。