Table of Contents
Nginx-Basics
1 , Environment:
2. Environment debugging confirmation:
1. Four confirmations
2. Two installations
Nginx is an open source, high-performance and reliable HTTP middleware, proxy service.
nginx -s reload -c /etc/nginx/conf: Restart
Home Backend Development PHP Tutorial Basic content about Nginx

Basic content about Nginx

May 07, 2018 am 10:57 AM
nginx content Base

This article mainly introduces the basic content about Nginx, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Nginx-Basics

1 , Environment:

  • System hardware: CPU>=2Core, Memory>=256M

  • Operating system: CentOS 7.2 x64


2. Environment debugging confirmation:

1. Four confirmations

  1. Confirm system network

  • ping www.baidu.com

  • Confirm that yum is available

    • yum list

  • Confirm to close iptables rules

    • iptables -L (check whether there are iptables rules)

    • iptables -F (Close the rules)

    • iptables -t nat -L (Check whether there are rules in the net table)

    • If there are rules in the net table, they can be executed: iptables -t nat -F

  • Confirm to disable selinux

    • getenforce (Check whether selinux is turned on)

    • setenforce 0 (Turn off selinux)

    2. Two installations

    • Install gcc, etc.:

      • ##yum -y install gcc gcc-c autoconf pcre pcre-devel make automake

    • Install basic tools:

      • ##yum -y install wget httpd-tools vim
      3. One-time initialization

      cd /opt;mkdir app download logs work backup
      • app: code directory
      • download: source code package downloaded from the Internet
      • logs: custom log
      • work: shell script
      • backup:Backup
    3. What is Nginx:

    Nginx is an open source, high-performance and reliable HTTP middleware, proxy service.

    4. Nginx advantages:

      IO multiplexing epoll
    1. Lightweight
      Few functional modules
    • Few code modules
    CPU affinity )
    • Bind the CPU core to the Nginx worker process, fix each worker process to execute on one CPU, reduce cache misses when switching CPUs, and obtain better performance .
    sendfile
    • Transmit the file to the user only through kernel space, not through user space
    5. Quick installation of Nginx

      Enter the official website http://nginx.org/
    1. Click download
    2. Click Linux packages for stable version
    3. ##Modify /etc/yum.repos.d/nginx.repo , and add the content specified by the official website
    4. Note
    : baseurl needs to modify the OS and OSRELEASE to your corresponding server version
    Directly yum install nginx
    1. nginx -v. If the nginx version information appears, the installation is successful!
    2. 6. Nginx directory and configuration syntax

    rpm -ql nginx: You can query the files installed by nginx
    • Directory
    • ##/etc/logrotate.d/nginx: Configuration file, Nginx log rotation, log cutting for logrotate service
      • /etc/nginx, /etc/nginx/nginx.conf, /etc/nginx/conf.d, /etc/nginx/conf.d/default.conf: directory, configuration file, Nginx main configuration file

      • /etc/nginx/fastcgi_params, /etc/nginx/uwsgi_params, /etc/nginx/scgi_params: configuration file, cgi configuration related, fastcgi configuration

      • /etc/nginx/koi-utf, /etc/nginx/koi-win, /etc/nginx/win-utf: configuration files, encoding conversion mapping conversion files

      • /etc/nginx/mime.types: Configuration file, set the corresponding relationship between the Content-Type of the http protocol and the extension

      • /usr/lib/systemd/system/ nginx-debug.service, /usr/lib/systemd/system/nginx.service, /etc/sysconfig/negix, /etc/sysconfig/negix-debug: Configuration files to configure the management method of the daemon manager

      • /usr/lib64/nginx/modules, /etc/nginx/modules: directory, Nginx module directory

      • /usr/sbin/nginx, /usr /sbin/nginx-debug: command, terminal command for startup management of Nginx service

      • /var/cache/nginx: directory, Nginx cache directory

      • /var/log/nginx: Directory, Nginx log directory

      • nginx -V:
    • Compilation parameters

    • --with-http_stub_status_module
      • --with-http_sub_module

      • - -with-http_random_index_module

      • --with-ld-opt=parameters

      • --with-cc-opt=parameters

      • --user=nginx

      • --group=nginx

      • --http-client-body-temp-path=/var/cache/nginx/client_temp

      • --http-proxy-temp-path=/var/cache/nginx/proxy_temp

      • ##--http-fastcgi-temp-path=/var /cache/nginx/fastcgi_temp

      • ##--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
      • -- http-scgi-temp-path=/var/cache/nginx/scgi_temp
      • --prefix=/etc/nginx
      • -- sbin-path=/usr/sbin/nginx
      • --modules-path=/usr/lib64/nginx/modules
      • -- conf-path=/etc/nginx/nginx.conf
      • --error-log-path=/var/log/nginx/error.log
      • --http-log-path=/var/log/nginx/access.log
      • --pid-path=/var/run/nginx.pid
      • --lock-path=/var/run/nginx.lock
      • ##Installation destination directory or path
      • Temporary files retained by nginx when executing the corresponding module
      • Set the user and user group for nginx process startup
      • Settings Additional parameters will be added to the CFLAGS variable
      • Set the additional parameters and link the system library
      • Randomly select a homepage in the directory
      • HTTP content replacement
      • Nginx client status
      • Nginx default configuration syntax
    • worker_connections: The maximum number of connections allowed per process
      • use: The number of worker processes
      • user: Set the system user for the nginx service
      • worker_processes: The number of worker processes (preferably consistent with the number of cpu)
      • error_log : nginx error log
      • pid: nginx service startup pid
      • events:
      7. Nginx log types

    Includes: error.log and access.log
    1. Configured through nginx.conf log_format in the file to define the variable format to be recorded to record the log
    2. Variables that can be recorded in the log
    3. Nginx built-in
    arg_PARAMETER: request parameter
    • http_HEADER: request header
    • sent_http_HEADER: header returned by the server
    HTTP request variable
    • Built-in variable
    • Custom variables
    8. Nginx module
    nginx -tc /etc/nginx/nginx.conf : Check whether the configuration file syntax is correct

    nginx -s reload -c /etc/nginx/conf: Restart


    http_stub_status_module (display Nginx related information)
    1. Configuration syntax: stub_status
    • Default: None
    • Context: server, location
    • random_index_module
  • Configuration syntax: random_index on|off
    • ##Default: random_index off

    • Context: location

    • http_sub_module
  • ##default: sub_filter_once on

    • on: only matches the first one, off: matches globally

    • ##default: sub_filter_last_modified off

    • default: None

      string: The string that needs to be replaced
    • replacement: replacement String
    • sub_filter string replacement

    ##sub_filter_last_modified on|off
    • sub_filter_once on|off
    • Note

      : The above Context: http, server, location

    limit_conn_module (connection frequency limit)
      Configuration syntax: limit_conn zone number
    1. Default: None
    • Context: http, server, location
    • Configuration syntax: limit_conn_zone key zone=name:size

    Default: None
    • Context: http
    • ##limit_conn_zone
    • limit_conn
    • limit_req_module (request frequency limit)
    • Configuration syntax: limit_req zone=name [brust=number] [ nodelay]
  • Default: None
    • Context: http, server, location

    • Configuration syntax: limit_req_zone key zone=name:size rate=rate
    • Default: None
    • Context: http

    • limit_req_zone
    • limit_req
    • ##http_access_module (IP-based access Control)

    • Configuration syntax: deny address|CIDR (network segment)|unix:|all;
  • Default: None

    • Context: http, server, location, limit_except

    • Configuration syntax: allow address|CIDR (network segment)|unix:|all;

    • Default: None

    • Context: http, server, location, limit_except

    • ##allow

    • ##deny
    Limitations

    : Access through a proxy will be invalid

      You can use http_x_forwarded_for
    • Combined with geo module
    • Passed through http custom variables
      http_auth_basic_module (User-based trust login)
      Configuration syntax: auth_basic_user_file filePath
    • Default: None
    • Context: http, server, location, limit_except
      Configuration syntax: auth_basic string | off;
    • Default: None
    • Context: http, server, location, limit_except
      auth_basic
    • auth_basic_user_file
    Note
    : The format of the file is specified, you can use httpd-tools# to generate the password ##Command:
    htpasswd -c filePath username

    The above is the detailed content of Basic content about Nginx. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

    You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

    How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

    How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

    How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

    How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

    How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

    How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

    How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

    Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

    How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

    Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

    How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

    The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

    How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

    Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

    See all articles