Basic content about Nginx
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
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
- cd /opt;mkdir app download logs work backup
- download: source code package downloaded from the Internet
- logs: custom log
- work: shell script
- backup:Backup
- app: code directory
Nginx is an open source, high-performance and reliable HTTP middleware, proxy service.
4. Nginx advantages:- IO multiplexing epoll
- Lightweight
- Few functional modules
- Few code modules
- 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 .
- Transmit the file to the user only through kernel space, not through user space
- Enter the official website http://nginx.org/
- Click download
- Click Linux packages for stable version
- ##Modify /etc/yum.repos.d/nginx.repo , and add the content specified by the official website
- Note
Directly yum install nginx
- nginx -v. If the nginx version information appears, the installation is successful!
- 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
-
- 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:
Includes: error.log and access.log
- Configured through nginx.conf log_format in the file to define the variable format to be recorded to record the log
- Variables that can be recorded in the log
- Nginx built-in
- http_HEADER: request header
- sent_http_HEADER: header returned by the server
- Built-in variable
- Custom variables
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)
- Configuration syntax: stub_status
- Default: None
- Context: server, location
- random_index_module
##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_once on|off
- Note
: The above Context: http, server, location
- Configuration syntax: limit_conn zone number
- Default: None
- Context: http, server, location
- Configuration syntax: limit_conn_zone key zone=name:size
- Context: http
- ##limit_conn_zone
- limit_conn
- limit_req_module (request frequency limit)
- Configuration syntax: limit_req zone=name [brust=number] [ nodelay]
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
- Configuration syntax: auth_basic string | off;
- Default: None
- Context: http, server, location, limit_except
- auth_basic
- auth_basic_user_file
: 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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? 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 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 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.

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".

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]

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.

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
