当前位置: 首页 > news >正文

做网站需要有服务器免费建网站

做网站需要有服务器,免费建网站,wordpress加图标,软件定制开发平台文章目录 1. 安装、启动、连接2. 快速尝试部署网站3. 配置文件1. nginx.conf全局配置事件模块HTTP 模块性能优化建议 2. default.confserver 块基本设置日志设置根路径设置 4. 反向代理1. 模拟3个Web2. 链接 5. 负载均衡1. 加权轮询#xff0c;Weighted Round Robin2. 最少连接… 文章目录 1. 安装、启动、连接2. 快速尝试部署网站3. 配置文件1. nginx.conf全局配置事件模块HTTP 模块性能优化建议 2. default.confserver 块基本设置日志设置根路径设置 4. 反向代理1. 模拟3个Web2. 链接 5. 负载均衡1. 加权轮询Weighted Round Robin2. 最少连接Least Connections3. IP哈希IP Hash4. 哈希Hash 6. HTTPS7. 虚拟主机 1. 安装、启动、连接 直接拿docker安装拉取镜像运行开放端口。 docker pull nginx:stable-perl虽然在容器中性能有所损失但是方便加快学习进度。 启动后浏览器访问localhost写着Welcome等欢迎语就是启动成功了。 在VSCode下载一些Docker常用插件然后就可以拿VSCode直接连上’正在运行的容器’和连接Linux服务器一样。 输入nginx -V查看nginx信息包括安装目录、编译参数、配置文件位置、日志文件位置等信息。可以看到配置文件位于--conf-path/etc/nginx/nginx.conf 。 rootf4f6c922d837:/# nginx -V nginx version: nginx/1.26.1 built by gcc 12.2.0 (Debian 12.2.0-14) built with OpenSSL 3.0.11 19 Sep 2023 TLS SNI support enabled configure arguments: --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 --usernginx --groupnginx --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 -Werrorformat-security -Wp,-D_FORTIFY_SOURCE2 -fPIC --with-ld-opt-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie2. 快速尝试部署网站 查看nginx配置文件可以找到如下部分。 server {listen 80;listen [::]:80;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location /50x.html {root /usr/share/nginx/html;} }这意味着nginx 把所有对服务器根路径的请求代理到 /usr/share/nginx/html 目录下并且把 index.html 或 index.htm 作为默认页面。 如果你使用Vue或者Hex开发网站它们的打包输出目录大致结构分别如下 dist/ ├── css/ │ └── app.12345.css ├── js/ │ └── app.12345.js ├── index.html └── favicon.icopublic/ ├── css/ │ └── style.css ├── js/ │ └── script.js ├── index.html ├── about/ │ └── index.html └── archives/└── index.html你只需要把dist或者public下的所有文件直接复制到/usr/share/nginx/html目录下重启nginx即可。 3. 配置文件 这个版本的nginx自带2个配置文件首先是nginx.conf。 如果你修改了配置文件可以用nginx -t来校验配置是否合法。然后使用nginx -s reload来重新加载配置文件。 1. nginx.conf 全局配置 user nginx; worker_processes auto;error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid;user 指令: 用法user username;描述指定 Nginx 运行时使用的系统用户。示例user nginx; 表示使用 nginx 用户。 worker_processes 指令: 用法worker_processes number|auto;描述设置工作进程数auto 会自动根据 CPU 核心数设置。示例worker_processes 4; 表示使用 4 个工作进程。 error_log 指令: 用法error_log file level;描述设置错误日志的路径和日志级别。日志级别选项 debug调试信息info一般信息notice通知信息默认warn警告信息error错误信息crit严重错误信息alert需要立即处理的问题emerg紧急情况 示例error_log /var/log/nginx/error.log notice; 表示记录通知级别及以上的日志。 pid 指令: 用法pid file;描述指定存储 Nginx 进程 ID 的文件路径。示例pid /var/run/nginx.pid; 表示将 PID 存储在 /var/run/nginx.pid 文件中。 可能改动的部分 worker_processes auto; 自动设置为 CPU 核心数适用于大多数情况。 可以手动设置为特定的进程数以微调性能但一般不需要。 事件模块 events {worker_connections 1024; }worker_connections 指令: 用法worker_connections number;描述设置每个工作进程允许的最大连接数。示例worker_connections 1024; 表示每个工作进程允许最多 1024 个连接。 可能改动的部分 worker_connections 1024; 默认设置为 1024适用于大多数小到中型网站。 对于高流量网站可以增加连接数以提高并发处理能力。 需要根据系统的 ulimit 设置进行调整确保系统支持更多的连接。 HTTP 模块 http {include /etc/nginx/mime.types;default_type application/octet-stream;log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;access_log /var/log/nginx/access.log main;sendfile on;#tcp_nopush on;keepalive_timeout 65;#gzip on;include /etc/nginx/conf.d/*.conf; }include 指令: 用法include file|directory;描述包含指定的文件或目录下的所有配置文件。示例include /etc/nginx/mime.types; 包含 MIME 类型配置文件。 default_type 指令: 用法default_type MIME-type;描述设置默认的 MIME 类型。示例default_type application/octet-stream; 表示未能确定文件类型时使用 application/octet-stream。 log_format 指令: 用法log_format name format; 描述定义日志格式。 示例 log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for;定义名为 main 的日志格式。 access_log 指令: 用法access_log file format;描述设置访问日志的路径和日志格式。示例access_log /var/log/nginx/access.log main; 使用 main 格式记录访问日志。 sendfile 指令: 用法sendfile on|off;描述启用或禁用 sendfile 选项用于提高文件传输效率。示例sendfile on; 启用 sendfile。 tcp_nopush 指令: 用法tcp_nopush on|off;描述用于优化传输数据时的 TCP 性能通常与 sendfile 一起使用。示例#tcp_nopush on; 默认注释掉。 keepalive_timeout 指令: 用法keepalive_timeout timeout;描述设置保持客户端连接的超时时间单位是秒。示例keepalive_timeout 65; 设置超时时间为 65 秒。 gzip 指令: 用法gzip on|off;描述启用或禁用 gzip 压缩。示例#gzip on; 默认注释掉。 include指令 用法include file|directory;描述include 指令用于包含其他配置文件或目录中的所有配置文件。这可以帮助将配置文件分割成更小的部分以便于管理和维护。示例 include /etc/nginx/mime.types;包含 MIME 类型配置文件。 include /etc/nginx/conf.d/*.conf;包含 /etc/nginx/conf.d/ 目录下的所有以 .conf 结尾的配置文件。 可能改动的部分 keepalive_timeout 65; 默认设置为 65 秒适用于大多数情况。 对于高并发的场景可以适当调低以减少资源占用。 tcp_nopush on; 通常注释掉如果启用可以优化数据传输尤其是在发送大文件时。 启用 tcp_nopush 后Nginx 会尝试将数据块一次性发送到网络而不是逐个包地发送从而减少包的数量提高传输效率。 通常与sendfile on;一起使用。启用 sendfile 后数据在内核空间中直接从一个文件描述符传输到另一个文件描述符避免了在用户空间和内核空间之间的多次拷贝从而提高了传输效率。 gzip on; 通常开启后可以启用 gzip 压缩以减少传输数据量提高传输速度。 启用后还需配置 gzip_types 和其他参数以确保正确压缩所需的文件类型。如 http {gzip on;gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xmlrss text/javascript; }其他 gzip 配置选项 gzip_min_length设置压缩的最小文件大小。gzip_comp_level设置压缩级别1-9级别越高压缩率越大但消耗的 CPU 资源更多。gzip_buffers设置用于存储压缩结果的缓冲区大小。gzip_vary设置 Vary: Accept-Encoding 响应头指示代理服务器和浏览器缓存可以根据请求的 Accept-Encoding 头进行不同的缓存。 Gzip 压缩是通过压缩算法如 DEFLATE将 HTTP 响应内容压缩成更小的体积然后再发送给客户端。解压缩的过程是nginx和浏览器自动完成的。 性能优化建议 增加 worker_connections 提高每个工作进程的最大连接数可以显著提升 Nginx 的并发处理能力。需要确保系统的文件描述符限制足够高。 启用 gzip 压缩 减少传输数据量尤其适用于文本类型的资源如 HTML、CSS、JavaScript。 配置示例 nginx 复制代码 gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xmlrss text/javascript; 优化 keepalive_timeout 在高并发情况下适当调低 keepalive 超时时间以减少长时间占用连接资源。 使用 tcp_nopush 和 tcp_nodelay 对于需要优化数据传输性能的场景可以启用 tcp_nopush 和 tcp_nodelay。 2. default.conf 好的让我们对 default.conf 文件的每一行进行解析 server 块 server {listen 80;listen [::]:80;server_name localhost;#access_log /var/log/nginx/host.access.log main;location / {root /usr/share/nginx/html;index index.html index.htm;}#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 /usr/share/nginx/html;} }基本设置 server { ... } 定义一个虚拟服务器块包含服务器的配置。 listen 80; 监听 IPv4 的 80 端口用于处理 HTTP 请求。 listen [::]:80; 监听 IPv6 的 80 端口用于处理 HTTP 请求。 server_name localhost; 定义服务器的名称为 localhost用于匹配请求的 Host 头。 日志设置 #access_log /var/log/nginx/host.access.log main; 配置访问日志的路径和格式此处被注释掉。如果启用将使用 main 日志格式记录访问日志。 根路径设置 location / { ... } 配置根路径即所有请求的处理方式。 root /usr/share/nginx/html; 指定请求的根目录为 /usr/share/nginx/html。 index index.html index.htm; 指定默认的索引文件为 index.html 或 index.htm。 4. 反向代理 正向代理是代理客户端客户端对于服务端来说是不可见的。 反向代理是代理服务端服务端对于客户端来说是不可见的。 1. 模拟3个Web docker pull python:3.9-slim在桌面或任意地方新建app.py内容为 from flask import Flask import osapp Flask(__name__)app.route(/) def hello():return fHello from the backend server running on port {os.environ.get(PORT)}!if __name__ __main__:app.run(host0.0.0.0, portint(os.environ.get(PORT, 5000))) 启动3个python容器模拟3个web服务。 C:\Users\mumu\Desktopdocker run --name web1 -d -e PORT8081 -p 8081:8081 -v /c/Users/mumu/Desktop/app.py:/app/app.py python:3.9-slim sh -c pip install flask python /app/app.py ab2ded77eafa82fbf4027f5714e5cb71bcb9775696f0e8c5423a70a7916a80acC:\Users\mumu\Desktopdocker run --name web2 -d -e PORT8082 -p 8082:8082 -v /c/Users/mumu/Desktop/app.py:/app/app.py python:3.9-slim sh -c pip install flask python /app/app.py e6c5321ea3926157dc2f2d9ed38df53c715da51c496c5ff0e7ff0c4e68c85696C:\Users\mumu\Desktopdocker run --name web3 -d -e PORT8083 -p 8083:8083 -v /c/Users/mumu/Desktop/app.py:/app/app.py python:3.9-slim sh -c pip install flask python /app/app.py f0bea8ac956af515fe35159fe94c86e919dfd566b782d06641472621a6299e26需要保证nginx和3个python在同一个docker网络中默认应该都是bridge。 2. 链接 使用docker inspect bridge查看刚才3个容器的ip。然后修改nginx的default.conf文件。 upstream backend {server 172.17.0.3:8081;server 172.17.0.4:8082;server 172.17.0.5:8083; }server {listen 80;listen [::]:80;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;}location /app {proxy_pass http://backend/;}error_page 500 502 503 504 /50x.html;location /50x.html {root /usr/share/nginx/html;} } upstream backend定义了一个名为 backend 的上游服务器组。 location /app { ... }配置如何处理以 /app 开头的所有请求。 proxy_pass http://backend/;将这些请求代理到上游服务器组 backend。请求的路径 /app 的前缀将被去除然后传递给上游服务器。例如/app/foo 将被代理为 /foo。 重启服务。 访问localhost/app并多次刷新试试。 5. 负载均衡 在不断刷新页面会发现反向代理是以“轮询”的方式将请求分发到3个web服务之一的。 除了轮询之外还有以下方式。 1. 加权轮询Weighted Round Robin 可以为不同的服务器设置权重权重越高服务器被请求的概率越大。 upstream backend {server 172.17.0.3:8081 weight3;server 172.17.0.4:8082 weight2;server 172.17.0.5:8083 weight1; }weight默认为1 。 2. 最少连接Least Connections 将请求分发给当前连接数最少的服务器适用于处理时间长、连接占用多的请求。 upstream backend {least_conn;server 172.17.0.3:8081;server 172.17.0.4:8082;server 172.17.0.5:8083; }3. IP哈希IP Hash 根据客户端 IP 地址进行哈希计算保证同一客户端的请求总是转发到同一台服务器适用于会话保持。 upstream backend {ip_hash;server 172.17.0.3:8081;server 172.17.0.4:8082;server 172.17.0.5:8083; }4. 哈希Hash 根据自定义的键值进行哈希计算来分发请求。 upstream backend {hash $request_uri;server 172.17.0.3:8081;server 172.17.0.4:8082;server 172.17.0.5:8083; }可以使用以下变量作为键值 $remote_addr客户端 IP 地址$request_uri请求的 URI$http_cookie请求的 Cookie ip_hash和hash $remote_addr一样都可以实现同一个客户端的请求分配到同一个后端服务器。但是一般这种情况使用前者更多。 6. HTTPS 首先要安装有openssl然后创建一个存放证书和私钥的文件夹比如mkdir C:\nginx\ssl 执行 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout C:\nginx\ssl\nginx-selfsigned.key -out C:\nginx\ssl\nginx-selfsigned.crt按问题填写信息就可以。 得到2个文件后复制到容器中比如/etc/nginx/ssl目录下然后再default.conf中添加一个server块如下 server {listen 443 ssl;listen [::]:443 ssl;server_name localhost;ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;location / {root /usr/share/nginx/html;index index.html index.htm;}location /app {proxy_pass http://backend/;}error_page 500 502 503 504 /50x.html;location /50x.html {root /usr/share/nginx/html;} }打开浏览器访问https://localhost 7. 虚拟主机 一个server块就是一个虚拟主机。 新建一个conf文件和default.conf同一目录。 upstream backend2 {server 172.17.0.3:8081 weight2;server 172.17.0.4:8082 weight2;server 172.17.0.5:8083 weight6; }server {listen 81;listen [::]:81;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;}location /app {proxy_pass http://backend2/;}error_page 500 502 503 504 /50x.html;location /50x.html {root /usr/share/nginx/html;} }重启服务浏览器访问http://localhost:81/app 。 利用这种方式我们可以在同一台机器上部署多个网站。
文章转载自:
http://www.morning.lynmt.cn.gov.cn.lynmt.cn
http://www.morning.wlbwp.cn.gov.cn.wlbwp.cn
http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn
http://www.morning.prddj.cn.gov.cn.prddj.cn
http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn
http://www.morning.jwrcz.cn.gov.cn.jwrcz.cn
http://www.morning.blqgc.cn.gov.cn.blqgc.cn
http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn
http://www.morning.rhkq.cn.gov.cn.rhkq.cn
http://www.morning.jrgxx.cn.gov.cn.jrgxx.cn
http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn
http://www.morning.kpfds.cn.gov.cn.kpfds.cn
http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn
http://www.morning.lmjtp.cn.gov.cn.lmjtp.cn
http://www.morning.hphqy.cn.gov.cn.hphqy.cn
http://www.morning.rcqyk.cn.gov.cn.rcqyk.cn
http://www.morning.ddqdl.cn.gov.cn.ddqdl.cn
http://www.morning.tzlfc.cn.gov.cn.tzlfc.cn
http://www.morning.yjprj.cn.gov.cn.yjprj.cn
http://www.morning.nxkyr.cn.gov.cn.nxkyr.cn
http://www.morning.hsjfs.cn.gov.cn.hsjfs.cn
http://www.morning.gkfwp.cn.gov.cn.gkfwp.cn
http://www.morning.rmtmk.cn.gov.cn.rmtmk.cn
http://www.morning.ityi666.cn.gov.cn.ityi666.cn
http://www.morning.rrcxs.cn.gov.cn.rrcxs.cn
http://www.morning.bksbx.cn.gov.cn.bksbx.cn
http://www.morning.xckrj.cn.gov.cn.xckrj.cn
http://www.morning.qrwdg.cn.gov.cn.qrwdg.cn
http://www.morning.nnmnz.cn.gov.cn.nnmnz.cn
http://www.morning.dgfpp.cn.gov.cn.dgfpp.cn
http://www.morning.llqky.cn.gov.cn.llqky.cn
http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn
http://www.morning.hmbxd.cn.gov.cn.hmbxd.cn
http://www.morning.kngqd.cn.gov.cn.kngqd.cn
http://www.morning.skwwj.cn.gov.cn.skwwj.cn
http://www.morning.dfkmz.cn.gov.cn.dfkmz.cn
http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn
http://www.morning.jhyfb.cn.gov.cn.jhyfb.cn
http://www.morning.smspc.cn.gov.cn.smspc.cn
http://www.morning.yxwrr.cn.gov.cn.yxwrr.cn
http://www.morning.dmldp.cn.gov.cn.dmldp.cn
http://www.morning.ccffs.cn.gov.cn.ccffs.cn
http://www.morning.spwm.cn.gov.cn.spwm.cn
http://www.morning.pwlxy.cn.gov.cn.pwlxy.cn
http://www.morning.mrkbz.cn.gov.cn.mrkbz.cn
http://www.morning.jcxgr.cn.gov.cn.jcxgr.cn
http://www.morning.pzbqm.cn.gov.cn.pzbqm.cn
http://www.morning.djpps.cn.gov.cn.djpps.cn
http://www.morning.fewhope.com.gov.cn.fewhope.com
http://www.morning.stprd.cn.gov.cn.stprd.cn
http://www.morning.dpsgq.cn.gov.cn.dpsgq.cn
http://www.morning.qhrsy.cn.gov.cn.qhrsy.cn
http://www.morning.lktjj.cn.gov.cn.lktjj.cn
http://www.morning.yuanshenglan.com.gov.cn.yuanshenglan.com
http://www.morning.kzxlc.cn.gov.cn.kzxlc.cn
http://www.morning.kpbq.cn.gov.cn.kpbq.cn
http://www.morning.qcnk.cn.gov.cn.qcnk.cn
http://www.morning.khyqt.cn.gov.cn.khyqt.cn
http://www.morning.dqpd.cn.gov.cn.dqpd.cn
http://www.morning.trlhc.cn.gov.cn.trlhc.cn
http://www.morning.sxtdh.com.gov.cn.sxtdh.com
http://www.morning.nflpk.cn.gov.cn.nflpk.cn
http://www.morning.fgsqz.cn.gov.cn.fgsqz.cn
http://www.morning.xnwjt.cn.gov.cn.xnwjt.cn
http://www.morning.njstzsh.com.gov.cn.njstzsh.com
http://www.morning.mmzhuti.com.gov.cn.mmzhuti.com
http://www.morning.fksrg.cn.gov.cn.fksrg.cn
http://www.morning.fqqcn.cn.gov.cn.fqqcn.cn
http://www.morning.prjty.cn.gov.cn.prjty.cn
http://www.morning.fydsr.cn.gov.cn.fydsr.cn
http://www.morning.mqxrx.cn.gov.cn.mqxrx.cn
http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn
http://www.morning.nnmnz.cn.gov.cn.nnmnz.cn
http://www.morning.rkfxc.cn.gov.cn.rkfxc.cn
http://www.morning.mlcnh.cn.gov.cn.mlcnh.cn
http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn
http://www.morning.ckcjq.cn.gov.cn.ckcjq.cn
http://www.morning.bfjtp.cn.gov.cn.bfjtp.cn
http://www.morning.srkwf.cn.gov.cn.srkwf.cn
http://www.morning.qtqk.cn.gov.cn.qtqk.cn
http://www.tj-hxxt.cn/news/244032.html

相关文章:

  • 建站推荐三线城市做网站需求
  • 上海建网站手机appwordpress $_file
  • 天气预报网站怎么做北京网站维护一般价格多少
  • 网站建设费用有哪些方面spark 网站开发
  • 网站标题几个字合适企业大全官网
  • asp网站如何发布网站 搭建 亚洲服务器
  • 余姚有专业做网站的吗成都网站设计平台
  • 织梦下载网站模板网站建设不包括哪个阶段
  • 桥西区附近网站建设价格汽车精品设计网站建设
  • 建设工程规划许可证网站姜堰 做网站
  • 网站建设的技术保证怎么写我有域名有服务器怎么建设网站
  • 济南自助建站软件湖北省建设质量安全协会网站
  • 深圳网站建设公司元翻译类公司网站模板
  • 邯郸网站设计多少钱林芝企业网站建设公司
  • qq空间钓鱼网站后台怎么做wordpress信息搜索插件
  • 南阳网站建设新闻网页设计师在哪里工作
  • wordpress如何建站呢中小企业做网站
  • 网站开发 软件有哪些wordpress支付宝双功能接口插件
  • 高端网站设计收费网站上怎么做推广
  • 如何本地搭建自己的网站建立的英文found
  • 专门做反季的网站泸州房地产新闻
  • 有没有专门做化妆品小样的网站网络营销常见的推广方式
  • 淮南餐饮网站建设从零开始学建设网站
  • 国家建设部网站官网证件查询彩票网站怎么样建设
  • 瑞安做企业网站找哪家企业年报系统登录
  • win7可以做网站吗公司网站建设方案模板
  • 培训加盟网站建设深圳优化企业
  • 天津建设交培训中心网站高档网站建
  • 域名和网站空间相互做解析2022百度seo优化工具
  • 企业网站app制作价格龙华网站 建设龙华信科