Nginx基础概念和常用操作?nginx的概念

Nginx基础概念和常用操作 文章目录 1. 安装、启动、连接2. 快速尝试部署网站3. 配置文件1. nginx.conf全局配置事件模块HTTP 模块性能优化建议 2. default.confserver 块基本设置日志设置根路径设置

文章目录

1. 安装、启动和连接2. 轻松尝试部署网站3. 配置文件1. nginx.conf 全局配置事件模块HTTP 模块性能优化建议

2.default.conf`server`块的基本设置日志设置根路径设置

4. 反向代理1. 模拟三个Web2 链接。

5. 负载平衡1. 最小连接数3. IP 哈希4.

6.HTTPS7.

1. 安装、启动、连接

只需直接安装docker,拉取并运行镜像,然后打开端口即可。

docker pull nginx:stable-perl

容器的性能成本稍低,但更方便并且使学习进度更快。

启动后,浏览器访问localhost,并写入欢迎信息,如“Welcome”,则表示启动成功。

一旦你用VSCode 下载了一些流行的Docker 插件,你就可以使用VSCode 直接连接到“正在运行的容器”,就像连接到Linux 服务器一样。

输入nginx -V 显示nginx信息,包括安装目录、编译参数、配置文件位置、日志文件位置等信息。可以看到配置文件位于–conf-path=/etc/nginx/nginx.conf。

root@f4f6c922d837:/# nginx -V

nginx 版本: nginx/1.26.1

使用gcc 12.2.0 (Debian 12.2.0-14) 构建

使用OpenSSL 3.0.11 构建2023 年9 月19 日

TLS SNI 支持已启用

配置argument: –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –modules-path=/usr/lib/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 –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 –user=nginx –group=nginx –with-compat –with-file-aio –with-threads –with-http_addition_module –with-http_auth_request_module –with-http_dav_module — with-http_flv_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_mp4_module –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_v3_module –with-mail –with-mail_ssl_module –with-stream –with-stream_realip_module –with-stream_ssl_module –with-stream_ssl_preread_module –with-cc-opt=\’-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.26.1/debian/debuild-base/nginx-1.26.1=-fstack-protector-strong -Wformat -Werror=格式-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC\’ –with-ld-opt=\’-Wl,-z,relro -Wl,-z,now -Wl,–as-needed -pie\’

2. 快速尝试部署网站

如果查看nginx 配置文件,您会发现以下部分:

服务器{

听80。

请听[:]:80;

服务器名称本地主机;

位置/{

根/usr/share/nginx/html;

索引index.htmlindex.htm;

}

错误页面500 502 503 504 /50x.html;

位置=/50x.html {

根/usr/share/nginx/html;

}

}

这意味着nginx会将所有到服务器根路径的请求代理到/usr/share/nginx/html目录,并使用index.html或Index.htm作为默认页面。

使用Vue或Hex开发网站时,打包后的输出目录一般结构如下:

距离/

CSS/

app.12345.css

js/

app.12345.js

index.html

favicon.ico

民众/

CSS/

样式.css

js/

脚本.js

index.html

关于/

index.html

档案/

index.html

只需将dist或public下的所有文件直接复制到/usr/share/nginx/html目录下,然后重新启动nginx即可。

3. 配置文件

这个版本的nginx自带两个配置文件,第一个是nginx.conf。

如果更改了配置文件,可以使用nginx -t 检查配置是否合法。然后使用nginx -s reload 重新加载配置文件。

原创文章,作者:CSDN,如若转载,请注明出处:https://www.sudun.com/ask/91849.html

(0)
CSDN的头像CSDN
上一篇 2024年6月23日
下一篇 2024年6月23日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注