Summary of nginx practices 1

Source: Internet
Author: User
Tags sendfile

1. Use the nginx installation script to explain how to install nginx

 
 
  1. #! /Bin/bash
  2. # Author zhangyifei
  3. #2013 2.27
  4. # Email zyfforlinux@163.com
  5. # Download the source code package
  6. Cd/usr/local/src
  7. Wget http://down1.chinaunix.net/distfiles/nginx-1.2.5.tar.gz
  8. Wget http://down1.chinaunix.net/distfiles/pcre-8.30.tar.bz2
  9. # Install the pcre Library to support nginx rewiter Regular Expressions
  10. Tar jxvf pcre-8.30.tar.bz2
  11. Cd pcre-8.30
  12. ./Configure
  13. Make & make install
  14. Cd ..
  15. Pcredir = "pcre-8.30"
  16. Soft = "nginx-1.2.5.tar.gz"
  17. Softdir = "nginx-1.2.5"
  18. If [-f $ soft]; then
  19. Tar zxvf $ soft
  20. Else
  21. Echo "$ soft not exis"
  22. Exit
  23. Fi
  24. # Check whether the ssl and status modules are installed.
  25. Read-p "do you install http_stub_status_module [Y/N]" args1
  26. Echo "$ args1"
  27. While ["$ args1 "! = "Y"] & ["$ args1 "! = "Y"] & ["$ args1 "! = "N"] & ["$ args1 "! = "N"]
  28. Do
  29. Read-p "please input [Y/N]" args1
  30. Done
  31.  
  32. If ["$ args1" = "Y"] | ["$ args1" = "y"]; then
  33. Args1 = "-- with-http_stub_status_module"
  34. Else
  35. Args1 = ""
  36. Fi
  37. Echo "$ args1"
  38. Read-p "do you install -- with-http_ssl_module [Y/N]" args2
  39. While ["$ args2 "! = "Y"] & ["$ args2 "! = "Y"] & ["$ args2 "! = "N"] & ["$ args2 "! = "N"]
  40. Do
  41. Read-p "please input [Y/N]" args2
  42. Done
  43. Echo "$ args2"
  44. If ["$ args2" = "Y"] | ["$ args2" = "y"]; then
  45. Args2 = "-- with-http_ssl_module"
  46. Else
  47. Args2 = ""
  48. Fi
  49. Echo "$ args2"
  50. # Create a user who starts nginx and cannot log on
  51. Nginxuser = "nginx"
  52. Useradd-s/sbin/nolgin $ nginxuser
  53. Cd $ softdir
  54. ./Configure -- prefix =/usr/local/nginx \
  55. -- User = $ nginxuser \
  56. -- Group = $ nginxuser \
  57. -- With-pcre =/usr/local/src/$ pcredir \
  58. $ Args1 $ args2
  59.  
  60. Make & make install

2. The following describes the default configuration file of nginx.

 

 
 
  1. # User nobody; specifies the user and user group that starts nginx
  2. Worker_processes 1; specify the number of processes that enable nginx and the logical cpu
  3.  
  4. # Error_log logs/error. log; location and format of error logs
  5. # Error_log logs/error. log notice;
  6. # Error_log logs/error. log info;
  7.  
  8. # Pid logs/nginx. pid; location of the process ID file
  9.  
  10.  
  11. Events {
  12. Worker_connections 1024; Maximum number of concurrent connections of a single backend worker process
  13. Use epoll; use the epoll mechanism to greatly improve nginx Performance
  14. }
  15.  
  16.  
  17. Http {
  18. Include mime. types; the type of html that can be processed.
  19. Default_type application/octet-stream;
  20.  
  21. Custom log format
  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.  
  26. # Access_log logs/access. log main;
  27. The sendfile command specifies whether nginx calls the sendfile function zero copy mode) to output files. For common applications,
    It must be set to on. If it is used for application disk I/O heavy load such as downloading, it can be set to off to balance disk and network I/O processing speed and reduce system uptime.
  28. Sendfile on;
  29. # Tcp_nopush on;
  30.  
  31. # Keepalive_timeout 0;
  32. Keepalive_timeout 65; keepalive timeout
  33.  
  34. # Gzip on; gzip enabled
  35.  
  36. Server {
  37. Listen 80; listening port
  38. Server_name localhost;
  39.  
  40. # Charset koi8-r;
  41.  
  42. # Access_log logs/host. access. log main;
  43.  
  44. Location /{
  45. Root html; set the root directory
  46. Index index.html index.htm; set the index starter File
  47. }
  48.  
  49. # Error_page 404/404 .html;
  50.  
  51. # Redirect server error pages to the static page/50x.html
  52. #
  53. Error_page 500 502 503 x.html; defines error file redirection
  54. Location =/50x.html {
  55. Root html;
  56. }
  57. }
  58. }

 

This article is from the blog "jeff for linux" and will not be reposted!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.