# 111111111111111111、安装所需环境
//安装gcc
yum install gcc-c++
//安装PCRE pcre-devel
yum install -y pcre pcre-devel
//安装zlib
yum install -y zlib zlib-devel
//安装Open SSL
yum install -y openssl openssl-deve
# 2、创建nginx目录并下载安装包
//进入usr/local目录
cd /usr/local
//创建nginx目录
mkdir nginx
//进入nginx目录
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
//解压tar
tar -xvf nginx-1.13.7.tar.gz
``
# 3、安装nginx
//进入nginx目录
cd /usr/local/nginx/nginx-1.13.7
//执行命令
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
//执行make命令(要是执行不成功请检查最开始安装的四个有没有安装成功)
make
//执行make install命令
make install
# 4、启动nginx
//进入/usr/local/nginx/sbin目录,输入./nginx即可启动nginx
./nginx
//关闭nginx
./nginx -s quit 或者 ./nginx -s stop
//重启nginx
./nginx -s reload
//查看nginx进程
ps -ef|grep nginx
# 5、设置开启自启动
//编辑
vim /etc/rc.local
//最底部增加这一行
/usr/local/nginx/sbin/nginx
# 6、环境变量
vim /etc/profile
最后一行加上
PATH=$PATH:/usr/local/nginx/sbin
export PATH
:wq 退出
nginx 启动
# 7、如果失败检测是否授权,再进行赋权
ls -l /etc/profile
sudo chmod +rx /etc/profile
source /etc/profile
nginx 再次启动
# 8、nginx.config 配置,新建并指定conf.d
sendfile on;
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 4096;
keepalive_timeout 65;
include /usr/local/nginx/conf/mime.types;
include /usr/local/nginx/conf/conf.d/*.conf;
# 9、nginx -t 可以查看是否安装成功
# 10、域名配置,这里有个地方要注意,域名在腾讯云买后,进行服务器ip跟域名进行绑定,代理的必须是ip:proxy_pass http://106.53.211.12,不能事localhost
server {
listen 443 ssl;
server_name www.jscdqygl.com;
#证书文件位置
ssl_certificate /etc/nginx/jscdqygl.com_bundle.crt;
#证书私钥文件位置
ssl_certificate_key /etc/nginx/jscdqygl.com.key;
client_max_body_size 200m;
#服务后端
location /notepad {
proxy_pass http://106.53.211.12:8080/notepad;
proxy_set_header Connection "Keep-Alive";
proxy_set_header Host $host;
#proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffer_size 5000k;
proxy_buffers 4 5000k;
proxy_connect_timeout 600s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
}
Linux上安装nginx
于 2024-01-04 16:13:33 首次发布