nginx 常用命令

  1. start nginx 启动nginx
  2. nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
  3. nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。
  4. nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。
  5. nginx -s reopen 重新打开日志文件。
  6. nginx -c filename Nginx 指定一个配置文件,来代替缺省的。
  7. nginx -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
  8. nginx -v 显示 nginx 的版本。
  9. 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. (1) Nginx配置路径:/etc/nginx/
  2. (2) PID目录:/var/run/[nginx.pid](https://www.centos.bz/tag/nginx-pid/)
  3. (3) 错误日志:/var/log/nginx/[error](https://www.centos.bz/tag/error/).log
  4. (4) 访问日志:/var/log/nginx/access.log
  5. (5) 默认站点目录:/usr/share/nginx/html

事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询
到。

配置文件

  1. #运行用户
  2. #user nobody;
  3. #启动进程,通常设置成和cpu的数量相等
  4. worker_processes 4;
  5. #全局错误日志及PID文件
  6. #error_log logs/error.log;
  7. #error_log logs/error.log notice;
  8. #error_log logs/error.log info;
  9. #pid logs/nginx.pid;
  10. #工作模式及连接数上限
  11. events {
  12. #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
  13. use epoll;
  14. #单个后台worker process进程的最大并发链接数
  15. worker_connections 1024;
  16. }
  17. #设定http服务器,利用它的反向代理功能提供负载均衡支持
  18. http {
  19. #设定mime类型,类型由mime.type文件定义
  20. include mime.types;
  21. default_type application/octet-stream;
  22. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  23. # '$status $body_bytes_sent "$http_referer" '
  24. # '"$http_user_agent" "$http_x_forwarded_for"';
  25. #access_log logs/access.log main;
  26. sendfile on;
  27. #tcp_nopush on;
  28. #keepalive_timeout 0;
  29. keepalive_timeout 65;
  30. #gzip on;
  31. server {
  32. listen 80;
  33. server_name localhost;
  34. #charset koi8-r;
  35. #access_log logs/host.access.log main;
  36. location / {
  37. root html;
  38. index index.html index.htm;
  39. }
  40. #error_page 404 /404.html;
  41. # redirect server error pages to the static page /50x.html
  42. #
  43. error_page 500 502 503 504 /50x.html;
  44. location = /50x.html {
  45. root html;
  46. }
  47. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  48. #
  49. #location ~ \.php$ {
  50. # proxy_pass http://127.0.0.1;
  51. #}
  52. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  53. #
  54. #location ~ \.php$ {
  55. # root html;
  56. # fastcgi_pass 127.0.0.1:9000;
  57. # fastcgi_index index.php;
  58. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  59. # include fastcgi_params;
  60. #}
  61. # deny access to .htaccess files, if Apache's document root
  62. # concurs with nginx's one
  63. #
  64. #location ~ /\.ht {
  65. # deny all;
  66. #}
  67. }
  68. # another virtual host using mix of IP-, name-, and port-based configuration
  69. #
  70. #server {
  71. # listen 8000;
  72. # listen somename:8080;
  73. # server_name somename alias another.alias;
  74. # location / {
  75. # root html;
  76. # index index.html index.htm;
  77. # }
  78. #}
  79. # HTTPS server
  80. #
  81. #server {
  82. # listen 443 ssl;
  83. # server_name localhost;
  84. # ssl_certificate cert.pem;
  85. # ssl_certificate_key cert.key;
  86. # ssl_session_cache shared:SSL:1m;
  87. # ssl_session_timeout 5m;
  88. # ssl_ciphers HIGH:!aNULL:!MD5;
  89. # ssl_prefer_server_ciphers on;
  90. # location / {
  91. # root html;
  92. # index index.html index.htm;
  93. # }
  94. #}
  95. }