1. web服务 apache iis
  2. django web框架
  3. lvs 负载均衡 章文嵩博士
  4. vue 尤雨溪
  5. Tengine
  6. F5 硬件负载
  7. A10
  1. ```
  2. wget http://nginx.org/download/nginx-1.16.1.tar.gz
  3. tar xf nginx-1.16.1.tar.gz
  4. cd nginx-1.16.1
  5. yum install gcc zlib2-devel pcre-devel openssl-devel
  6. ./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module
  7. make && make install
  8. ```
  1. ```
  2. [root@localhost nginx]#ls
  3. conf html logs sbin
  4. conf 配置文件
  5. html 存放静态文件 index.html 是默认的欢迎页面
  6. logs 日志目录
  7. sbin 二进制文件
  8. 启动以后会生成一个主进程,根据配置文件的选项来生成子进程(工作进程),主进程不负责处理用户的请求,用来转发用户的请求,真正负责处理用户请求的是子进程
  9. ```
  1. ```
  2. ./sbin/nginx -h
  3. nginx version: nginx/1.16.1
  4. Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
  5. Options:
  6. -?,-h : this help
  7. -v : show version and exit 显示版本号
  8. -V : show version and configure options then exit 显示版本+编译时选项
  9. -t : test configuration and exit 测试配置文件
  10. -T : test configuration, dump it and exit
  11. -q : suppress non-error messages during configuration testing
  12. -s signal : send signal to a master process: stop, quit, reopen, reload
  13. -p prefix : set prefix path (default: /opt/nginx/)
  14. -c filename : set configuration file (default: conf/nginx.conf)
  15. -g directives : set global directives out of configuration file
  16. ```
  1. ```shell
  2. #user nobody; 使用哪个用户来启动子进程
  3. worker_processes 1; #工作进程的个数,配置成cpu的核心数-1或者-2
  4. # cpu亲缘性绑定,让nginx的子进程工作在哪个核心上
  5.  
  6. #error_log logs/error.log;
  7. #error_log logs/error.log notice;
  8. #error_log logs/error.log info;
  9.  
  10. #pid logs/nginx.pid;
  11. events {
  12. #use [epoll|select|poll];
  13. worker_connections 102400; # 每一个子进程可以处理的连接数
  14. }
  15. http {
  16. include mime.types; #导入
  17. default_type application/octet-stream; # 默认的请求方式
  18. # 定义日志格式
  19. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  20. # '$status $body_bytes_sent "$http_referer" '
  21. # '"$http_user_agent" "$http_x_forwarded_for"';
  22. #定义日志并定义日志格式
  23. #access_log logs/access.log main;
  24. sendfile on;
  25. #tcp_nopush on;
  26.  
  27. #keepalive_timeout 0;
  28. keepalive_timeout 65; # 保持长连接的超时时间
  29.  
  30. #gzip on;
  31. server {
  32. listen 80; #监听端口
  33. server_name localhost;
  34. #charset koi8-r;
  35.  
  36. #access_log logs/host.access.log main;
  37. location / {
  38. root html; # 指定静态文件地址
  39. index index.html index.htm; # 指定默认的index页面
  40. }
  41. # 错误页面 找不到页面
  42. #error_page 404 /404.html;
  43.  
  44. # redirect server error pages to the static page /50x.html
  45. #
  46. # 错误页面 服务端错误
  47. error_page 500 502 503 504 /50x.html;
  48. location = /50x.html {
  49. root html;
  50. }
  51. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  52. #
  53. #location ~ \.php$ {
  54. # proxy_pass http://127.0.0.1;
  55. #}
  56.  
  57. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  58. #
  59. #location ~ \.php$ {
  60. # root html;
  61. # fastcgi_pass 127.0.0.1:9000;
  62. # fastcgi_index index.php;
  63. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  64. # include fastcgi_params;
  65. #}
  66.  
  67. # deny access to .htaccess files, if Apache's document root
  68. # concurs with nginx's one
  69. #
  70. #location ~ /\.ht {
  71. # deny all;
  72. #}
  73. }
  74. # another virtual host using mix of IP-, name-, and port-based configuration
  75. #
  76. #server {
  77. # listen 8000;
  78. # listen somename:8080;
  79. # server_name somename alias another.alias;
  80.  
  81. # location / {
  82. # root html;
  83. # index index.html index.htm;
  84. # }
  85. #}
  86.  
  87.  
  88. # HTTPS server
  89. #
  90. #server {
  91. # listen 443 ssl;
  92. # server_name localhost;
  93.  
  94. # ssl_certificate cert.pem;
  95. # ssl_certificate_key cert.key;
  96.  
  97. # ssl_session_cache shared:SSL:1m;
  98. # ssl_session_timeout 5m;
  99.  
  100. # ssl_ciphers HIGH:!aNULL:!MD5;
  101. # ssl_prefer_server_ciphers on;
  102.  
  103. # location / {
  104. # root html;
  105. # index index.html index.htm;
  106. # }
  107. #}
  108. }
  109. ```
  1. ```
  2. error_page 404 /404.html;
  3. ```
  1. ```
  2. location /img {
  3.   root /data/img;
  4. }
  5. root /data/img 里面必须有/img
  6. location /img {
  7.   alias /data/img;
  8. }
  9. alias /data/img 里面不需要有 /img
  10. ```
  1. ```
  2. server_name mynginx.com
  3. ```
  1. ```
  2. server {
  3.   listen 80;
  4.   server_name www.taobao.com taobao.com;
  5.   location / {
  6.     root /data/taobao;
  7.     index index.html;
  8.   }
  9. }
  10. server {
  11.   listen 80;
  12.   server_name www.jd.com jd.com;
  13.   location / {
  14.     root /data/jd;
  15.     index index.html;
  16.   }
  17. }
  18. ```
  1. ```
  2. listen 80 default_server; #放在server中的端口号后面,在使用ip访问时,默认访问的server
  3. ```

 

版权声明:本文为sun-10387834原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/sun-10387834/p/12790766.html