Liunx-CentOS安装Nginx
作者:互联网
0 卸载Nginx
# 查看nginx是否运行
ps -ef | grep nginx
# 停止用stop、或者用kill
/usr/local/nginx/sbin/nginx -s stop
# 查询Nginx安装的文件
find / -name nginx
# 删除Nginx的相关文件
rm -rf /usr/local/nginx
... 全部删除 ...
如果设置了Nginx开机自启动的话,可能还需要下面两步
chkconfig nginx off
rm -rf /etc/init.d/nginx
可以再用yum指令清理
yum remove nginx
1 Ninx安装包
官方下载:https://nginx.org/en/download.html
上传服务器
2 安装依赖
gcc
yum install -y gcc
perl库
yum install -y pcre pcre-devel
zlib库
yum install -y zlib zlib-devel
openssl
yum install -y penssl openssl-devel
或者直接一条命令
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
3 安装Nginx
# 解压
tar -zxvf nginx-1.22.0.tar.gz
# 进入解压目录
cd nginx-1.22.0
# 开始编译安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
4 访问测试
localhost出现nginx页面则成功
可以删除源码目录
到此安装完毕
5 conf.d
# 新建
mkdir conf.d
chmod 666 conf.d
...
在conf.d中添加server
server {
listen 8009;
server_name localhost;
root html;
index index.html index.htm;
location ^~ /w-server/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8008/w-server/;
}
location ^~ /w-admin/ {
alias /mnt/wlt/html/dist/;
index index.html;
try_files $uri $uri/=404 /index.html last;
}
}
原配置文件http{}中添加
include /usr/local/nginx/conf.d/*.conf;
重启Nginx
/usr/local/nginx/sbin/nginx -s reload
6 环境变量
vim /etc/profile
#Nginx enviroment
export NGINX_HOME=/usr/local/environment/nginx1.22
export PATH=$NGINX_HOME/sbin:$PATH
source /etc/profile
nginx -v
7 相关命令
# 重新载入配置文件
nginx -s reload
# 重启 Nginx
nginx -s reopen
# 停止 Nginx
nginx -s stop
标签:index,CentOS,nginx,devel,Nginx,yum,Liunx,local 来源: https://www.cnblogs.com/a999/p/16345734.html