Nginx安装配置及端口转发
简介
Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。
在我们实际开发应用中,需要了解Nginx的以下几个功能
- 正向代理
- 反向代理
- 负载均衡
- 动静分离
- 端口转发
域名简介
域名就是网站:www.xmmup.com就是域名
DNS域名解析服务器,把域名解析为ip地址。保存的就是域名和ip地址的映射关系。
一级域名:xmmup.com
二级域名:www.xmmup.com
三级域名:pic.xmmup.com
一个域名对应与一个ip地址,一个ip地址可以被多个域名绑定。
只需要买一个一级域名,后面的二级,三级域名你自己可以随便定义。
下载
http://nginx.org/en/download.html
官网提供三种版本:
Nginx官网提供了三个类型的版本
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老版本的稳定版
Linux环境安装
由于nginx是基于c语言开发的,所以需要安装c语言的编译环境。
yum安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install -y nginx* nginx-mod-devel nginx-mod-stream nginx-all-modules systemctl enable nginx systemctl start nginx systemctl status nginx -- 默认配置文件 /etc/nginx/nginx.conf -- 日志 /var/log/nginx/error.log [root@lhrxxt ~]# netstat -tulnp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23092/nginx: master tcp6 0 0 :::80 :::* LISTEN 23092/nginx: master [root@lhrxxt ~]# [root@lhrxxt ~]# nginx -V nginx version: nginx/1.20.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021 TLS SNI support enabled configure arguments: --prefix=/usr/share/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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' [root@lhrxxt ~]# |
1、Linux release 7.6.1810 会安装nginx-1.20.1版本。