电商网站的支付模块怎么做,滨河网站建设,wordpress企业建,网站首页弹窗代码nginx搭建个人网站 Nginx是一款轻量级Web服务器、反向代理服务器以及电子邮件代理服务器#xff0c;并且具有高并发连接处理能力和低内存消耗的特点。它也可以用于负载均衡和缓存控制等功能。 功能#xff1a; 静态网站服务器#xff1a;Nginx可以用来作为静态网站服务器并且具有高并发连接处理能力和低内存消耗的特点。它也可以用于负载均衡和缓存控制等功能。 功能 静态网站服务器Nginx可以用来作为静态网站服务器支持HTML、CSS、JavaScript等静态文件。 动态网站服务器通过安装PHP、Python等解释器Nginx可以作为动态网站服务器支持动态页面生成。 反向代理服务器Nginx可以作为反向代理服务器接收来自客户端的请求然后将请求转发到后端的服务器上返回的结果再返回给客户端。 负载均衡Nginx可以用来作为负载均衡器将客户端的请求分发到多个后端服务器上提高网站的并发处理能力。 邮件代理Nginx可以作为邮件代理服务器支持IMAP和POP3协议可以用来接收和转发邮件。 安装方式 1、yum 安装 2、rpm 3、源码编译安装 4、docker部署安装 环境 Centos8 本次采用yum进行安装适合新手学习。 部署 # 确定服务器可以访问外网
# 更新yum源
yum update -y# 安装
yum install nginx# 使用systemctl管理nginx服务
systemctl start nginx# 设置开机启动
systemctl enable nginx# 查看nginx服务状态
systemctl status nginx# 如果防火墙开启的话需要放通端口
firewall-cmd --zonepublic --add-port80/tcp --permanent
firewall-cmd --reloadnginx配置文件路径 # 配置文件一般情况下位于/etc/nginx/nginx.conf,整个目录包含主配置文件nginx.conf和其他配置文件
root761e1b942a26:/etc/nginx# ls -la
total 24
drwxr-xr-x 1 root root 20 Dec 29 2021 .
drwxr-xr-x 1 root root 19 Nov 13 04:25 ..
drwxr-xr-x 1 root root 26 Nov 13 04:25 conf.d # 配置目录一般在主配置文件包含
-rw-r--r-- 1 root root 1007 Dec 28 2021 fastcgi_params
-rw-r--r-- 1 root root 5349 Dec 28 2021 mime.types # 网页文本类型配置一般不需要修改
lrwxrwxrwx 1 root root 22 Dec 28 2021 modules - /usr/lib/nginx/modules # nginx模块
-rw-r--r-- 1 root root 648 Dec 28 2021 nginx.conf # 主配置文件
-rw-r--r-- 1 root root 636 Dec 28 2021 scgi_params
-rw-r--r-- 1 root root 664 Dec 28 2021 uwsgi_params# 网页服务器主目录一般在/usr/share/nginx,包括html目录以及对应index.html文件等
root761e1b942a26:/usr/share/nginx/html# ls
50x.html index.html# 默认的nginx日志目录/var/log/nginx,包括访问日志和错误日志根据主配置文件中定义
root761e1b942a26:/var/log/nginx# ls
access.log error.log一般情况下的配置 通过主配置文件定义web服务器的端口和参数然后将网站资源文件放到服务器网页目录上即可。 nginx配置文件示例 配置文件才能模块方式编写使用{}进行同一区块分别,使用#进行注释。 Main Block: 主区块是一个配置文件的顶层区块其中包含了对整个Nginx服务器的基础配置如错误日志文件的位置、PID文件的位置、工作进程的数量等。 Events Block: 事件区块用于定义如何处理网络连接和处理请求如采用哪种工作模型、最大连接数量、是否启用多线程等。 Http Block: Http区块是用于定义HTTP协议相关的配置例如MIME类型、访问控制、错误页面重定向等。 Server Block: 服务器区块用于定义特定的虚拟主机或者应用程序它可以包含子区块如Location Block来更具体地定义URL匹配规则和路由。 Upstream Block: 负载均衡器区块用于定义后端服务器集群的相关信息如集群成员、轮询策略、健康检查等。 # 定义启动nginx服务器的用户以及进程数量
user nginx;
worker_processes auto;
# 定义错误日志和pid路径
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;# 工作进程连接数
events {worker_connections 1024;
}# http块定义了包含server块的整体定义如显示版本号是否开启压缩日志格式等
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 定义了引用指定目录下的配置文件一般将server块单独定义一个网站一个server配置文件。include /etc/nginx/conf.d/*.conf;
}# server块可以在conf.d目录下新建一个xx.conf的文件写入内容。
server {listen 80; # 表示侦听80端口有几种写法如果多个ip地址可以指定地址否则全部侦听listen [::]:80; # 侦听ipv6server_name localhost; # 域名内网可以直接写ip地址外网有dns可以写认证域名# 单独定义这个server的日志#access_log /var/log/nginx/host.access.log main;# location定义了网页根目录以及网页默认文件类型index.htmllocation / {root /usr/share/nginx/html;index index.html index.htm;}# 定义特定404页面返回文件#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;}# 配置PHP代理实现动态网站搭建# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apaches document root# concurs with nginxs one##location ~ /\.ht {# deny all;#}
}本文由 mdnice 多平台发布