Nginx

常用命令

cd/usr/local/nginx/sbin

./nginx 启动

.nginx -s stop 停止

.nginx -s quit 安全退出

./nginx -s reload 重新加载配置文件

ps aux|grep nginx 查看nginx进程

配置

配置详解: https://www.cnblogs.com/knowledgesea/p/5175711.html

  1. # 全局配置
  2. # 监听事件
  3. events {
  4. worker_connections 1024;
  5. }
  6. # http配置
  7. http {
  8. #http的全局配置
  9. upstream 名称{
  10. //负载均衡配置
  11. # 服务器资源
  12. server 127.0.0.1:8080 weight=权重;
  13. server 127.0.0.1:8081 weight=权重;
  14. }
  15. server {
  16. listen 81;
  17. server_name localhost;
  18. //代理
  19. location / {
  20. 80端口的根目录
  21. 128服务器
  22. proxy_pass http://名称
  23. }
  24. HTTP://localhost:8080/admin
  25. location /admin {
  26. 47服务器
  27. }
  28. }
  29. server {
  30. listen 443;
  31. server_name localhost;
  32. //代理
  33. }
  34. }
  35. https配置
  36. # https
  37. # HTTPS server
  38. #
  39. #server {
  40. # listen 443 ssl;
  41. # server_name localhost;
  42. #}
  43. }
  1. ########### 每个指令必须有分号结束。#################
  2. #user administrator administrators; #配置用户或者组,默认为nobody nobody。
  3. #worker_processes 2; #允许生成的进程数,默认为1
  4. #pid /nginx/pid/nginx.pid; #指定nginx进程运行文件存放地址
  5. error_log log/error.log debug; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
  6. events {
  7. accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
  8. multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
  9. #use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
  10. worker_connections 1024; #最大连接数,默认为512
  11. }
  12. http {
  13. include mime.types; #文件扩展名与文件类型映射表
  14. default_type application/octet-stream; #默认文件类型,默认为text/plain
  15. #access_log off; #取消服务日志
  16. log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定义格式
  17. access_log log/access.log myFormat; #combined为日志格式的默认值
  18. sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
  19. sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
  20. keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。
  21. upstream mysvr {
  22. server 127.0.0.1:7878;
  23. server 192.168.10.121:3333 backup; #热备
  24. }
  25. error_page 404 https://www.baidu.com; #错误页
  26. server {
  27. keepalive_requests 120; #单连接请求上限次数。
  28. listen 4545; #监听端口
  29. server_name 127.0.0.1; #监听地址
  30. location ~*^.+$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
  31. #root path; #根目录
  32. #index vv.txt; #设置默认页
  33. proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表
  34. deny 127.0.0.1; #拒绝的ip
  35. allow 172.18.5.54; #允许的ip
  36. }
  37. }
  38. }