Get the App
SLTechnology News&Howtos  ›  Servers  › 

Nginx Learning Notes (1)

Shulou Source: shulou.com Published: 2022-06-03 04:26:26 09月11日 Update

Nginx Learning Notes (1)

I. the characteristics and functions of Nginx

Nginx can respond to requests more quickly.

Web and reverse proxy server

Support a wide range of server software features

Dealing with static resources

Used as a reverse proxy

Used as load balancer

II. Nginx compilation and installation

2.1 preparation work

Operating system: CentOS7.3 IP address: 10.0.0.110

Yum install-y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

2.2 add users

Useradd-r nginx

2.3 compilation and installation

/ configure-- prefix=/usr/local/nginx-- 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-- user=nginx-- group=nginx-- with-http_ssl_module-- with-http_v2_module-- with-http_dav_module-- With-http_stub_status_module-with-threads-with-file-aio

Make & & make install

Third, simple web site configuration

3.1 set environment variables

Vi / etc/profile.d/nginx.sh # adds the following fields to the last line

Export PATH= "$PATH:/usr/local/nginx/sbin/"

3.2 start nginx

Nginx

3.3.Configuring web sites for nginx

Description: the root directory of the site A:www.huwho.cn URL map: / nginx/web

The root directory of the site B:blog.huwho.cn URL map: / nginx/blog

Compile configuration file

Vi / etc/nginx.conf

The site A configuration segment is as follows:

Server {listen 80; server_name www.huwho.cn; root / nginx/web; index index.html; # charset koi8-r; # access_log logs/host.access.log main; location / p_w_picpaths/ {root / nginx/;} # error_page 404 / 404.html # redirect server error pages to the static page / 50x.html # error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html;}

The site B configuration segment is as follows:

Server {listen 80; server_name blog.huwho.cn; root / nginx/blog; index index.html; error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html;}}

3.4Test nginx syntax

[root@pxe31 nginx] # nginx-tnginx: the configuration file / etc/nginx/nginx.conf syntax is oknginx: configuration file / etc/nginx/nginx.conf test is successful

3.5 overload nginx

[root@pxe31 nginx] # nginx-s reload

3.6 site directory and file configuration

Mkdir / nginx/ {web,blog}

Echo www.huwho.cn > / nginx/web/index.html

Echo blog.huwho.cn > / nginx/blog/index.html

3.7 modify the hosts file of windows

3.8 access Test

Tags: Site configuration file compilation server root agent service test note learning equalization operating system one line function variable address field faster feature Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology NVidia Apple MariaDB