Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx Learning Notes (1)

2025-03-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report