nginx 常用命令
start nginx 启动nginxnginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。nginx -s reopen 重新打开日志文件。nginx -c filename 为 Nginx 指定一个配置文件,来代替缺省的。nginx -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。nginx -v 显示 nginx 的版本。nginx -V 显示 nginx 的版本,编译器版本和配置参数
常用命令
(1) 启动:./nginx
(2) 测试Nginx配置是否正确:./nginx -t
(3) 优雅重启:./nginx -s reload
(4) 查看nginx的进程号:ps -ef | grep nginx
(5)nginx服务停止./nginx -s stop
kill -9 pid 杀死进程,一般情况下禁止使用此种方法。可能会导致主进程被杀死,workpress依然存在的情况。可以使用kill -15 pid。
nginx默认路径
(1) Nginx配置路径:/etc/nginx/(2) PID目录:/var/run/[nginx.pid](https://www.centos.bz/tag/nginx-pid/)(3) 错误日志:/var/log/nginx/[error](https://www.centos.bz/tag/error/).log(4) 访问日志:/var/log/nginx/access.log(5) 默认站点目录:/usr/share/nginx/html
事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询
到。
配置文件
#运行用户#user nobody;#启动进程,通常设置成和cpu的数量相等worker_processes 4;#全局错误日志及PID文件#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;#工作模式及连接数上限events {#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能use epoll;#单个后台worker process进程的最大并发链接数worker_connections 1024;}#设定http服务器,利用它的反向代理功能提供负载均衡支持http {#设定mime类型,类型由mime.type文件定义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;server {listen 80;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;# }#}}
