您现在的位置是:主页 > news > 桂林网站开发公司电话/湛江seo网站管理
桂林网站开发公司电话/湛江seo网站管理
admin2025/6/15 17:00:12【news】
简介桂林网站开发公司电话,湛江seo网站管理,个人网站建设详细教程,如何判断网站html5文章目录Nginx特点安装Nginx启动Nginx常用命令Nginx 配置文件内容Nginx 配置反向代理-实例Nginx 配置Nginx配置高可用集群Nginx原理在这个开发即运维的时代,Nginx 属于必会技能。 Nginx特点 (1)反向代理 (2)负载均衡…
桂林网站开发公司电话,湛江seo网站管理,个人网站建设详细教程,如何判断网站html5文章目录Nginx特点安装Nginx启动Nginx常用命令Nginx 配置文件内容Nginx 配置反向代理-实例Nginx 配置Nginx配置高可用集群Nginx原理在这个开发即运维的时代,Nginx 属于必会技能。
Nginx特点
(1)反向代理 (2)负载均衡…
文章目录
- Nginx特点
- 安装Nginx
- 启动Nginx
- 常用命令
- Nginx 配置文件内容
- Nginx 配置反向代理-实例
- Nginx 配置
- Nginx配置高可用集群
- Nginx原理
在这个开发即运维的时代,Nginx 属于必会技能。
Nginx特点
(1)反向代理
(2)负载均衡
(3)动静分离
安装Nginx
安装Nginx依赖包:
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
Nginx下载地址:https://nginx.org/
下载,解压,配置检查
wget https://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure
可以看到一些有用的信息:
Configuration summary+ using system PCRE library+ OpenSSL library is not used+ using system zlib librarynginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"
安装Nginx :
make && make install
启动Nginx
cd /usr/local/nginx/sbin
./nginx
看看有没有启动成功:
可以看看进程:
ps -aux|grep nginx
或者可以直接访问80端口:
因为cat /usr/local/nginx/conf/nginx.conf
里面写了:
浏览器输入 IP:80
搞定CentOS防火墙:
查看防火墙状态
firewall-cmd --state
停止firewall
systemctl stop firewalld.service
禁止firewall开机启动
systemctl disable firewalld.service
查看防火墙开放的端口号:
firewall-cmd --list-all
设置开放防火墙端口号:
firewall-cmd --add-service=http --permanent
firewall-cmd --add-port=80/tcp --permanent
重启防火墙:
firewall-cmd --reload
常用命令
需要进入到sbin目录中去执行这些命令,其实就是sbin里面有nginx入口。
cd /usr/local/nginx/sbin
基本参数:
(base) [root@localhost sbin]# ./nginx -h
nginx version: nginx/1.20.1
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix][-e filename] [-c filename] [-g directives]Options:-?,-h : this help-v : show version and exit-V : show version and configure options then exit-t : test configuration and exit-T : test configuration, dump it and exit-q : suppress non-error messages during configuration testing-s signal : send signal to a master process: stop, quit, reopen, reload-p prefix : set prefix path (default: /usr/local/nginx/)-e filename : set error log file (default: logs/error.log)-c filename : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration file
基本命令:
./nginx -v # 查看版本号
./nginx -s stop # 停止nginx
./nginx -s reload # 重加载nginx,配置文件会重新加载生效
./nginx # 直接启动nginx
Nginx 配置文件内容
vim /usr/local/nginx/conf/nginx.conf
全局块:
events块:
http块:
其中又含有http全局块和http的server块。
Nginx 配置反向代理-实例
docker run -d -p 8080:8080 tomcat # 在Linux中启动一个tomcat服务vim /usr/local/nginx/conf/nginx.conf # 编辑配置文件
./nginx -s reload
这个时候再访问这台服务器的80端口的服务,会看到是tomcat的服务页面。
Nginx 配置
参考:https://www.runoob.com/w3cnote/nginx-setup-intro.html
参考:https://www.nginx.cn/doc/
########### 每个指令必须有分号结束。#################
#user administrator administrators; #配置用户或者组,默认为nobody nobody。
#worker_processes 2; #允许生成的进程数,默认为1
#pid /nginx/pid/nginx.pid; #指定nginx进程运行文件存放地址
error_log log/error.log debug; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
events {accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为onmulti_accept on; #设置一个进程是否同时接受多个网络连接,默认为off#use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventportworker_connections 1024; #最大连接数,默认为512
}
http {include mime.types; #文件扩展名与文件类型映射表default_type application/octet-stream; #默认文件类型,默认为text/plain#access_log off; #取消服务日志 log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定义格式access_log log/access.log myFormat; #combined为日志格式的默认值sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。upstream mysvr { server 127.0.0.1:7878;server 192.168.10.121:3333 backup; #热备}error_page 404 https://www.baidu.com; #错误页server {keepalive_requests 120; #单连接请求上限次数。listen 4545; #监听端口server_name 127.0.0.1; #监听地址 location ~*^.+$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。#root path; #根目录#index vv.txt; #设置默认页proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表deny 127.0.0.1; #拒绝的ipallow 172.18.5.54; #允许的ip } }
}