-----------------------------------------------安装--------------------------------------------------------
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
nginx下载地址:https://nginx.org/download/
--解压
tar -zxvf nginx-1.9.9.tar.gz 或者 tar -zxvf nginx-1.9.9.tar.gz -C /home/nginx
--进入nginx目录
cd nginx-1.9.9
--配置
./configure --prefix=/usr/local/nginx
--make
make
make install
--检测是否安装成功到/usr/local/nginx目录下
./sbin/nginx -t
---下面根据情况进行配置(可不用配置)
--开启80端口:
firewall-cmd --add-port=80/tcp --permanent
#重启防火墙
systemctl restart firewalld
--配置nginx开机自启动
vim /etc/rc.d/rc.local
文件中添加 /usr/local/nginx/sbin/nginx
----------------------------------------------nginx常用操作---------------------------------------------------
到nginx的安装目录下
--快速停止或关闭Nginx:./nginx -s stop
--正常停止或关闭Nginx:./nginx -s quit
--配置文件修改重装载命令:nginx -s reload
-------------------------------删除nginx相关的所有配置(用于重装nginx)-----------------------------------------
--停止nginx
service nginx stop
--删除nginx自动启动
chkconfig nginx off
--从源头删除Nginx (whereis nginx)
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
--再使用yum清理
yum remove nginx
---------------------------------------conf相关的配置介绍--------------------------------------------------------
目录在nginx安装目录的conf/nginx.conf下
-- 重点配置
#test1 采用这种方式有助于后面增加负载,hash或其它负载方式
upstream test1sss {
server localhost:8090; # 对应当前本机tomcat1(测试)
}
#test2
upstream test2sss {
server localhost:8091; # 对应当前本机tomcat2(测试)
}
server {
# 监听80端口
listen 80;
server_name www.pytest1.xxx.com pytest1.xxx.com;
access_log on;
#charset koi8-r;
charset utf-8;
# 不加有时是不会显示目录的
autoindex on;
#access_log logs/host.access.log main;
location /test1 {
proxy_pass http://test1sss/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#
location /test2 {
proxy_pass http://test2sss/;
proxy_set_header Host $host;
proxy_connect_timeout 5s;
}
location / {
root html;
index index.html index.htm;
}
# 此处访问地址为/home/dist1
location /dist1 {
alias /home/dist1/;
index index.html index.htm;
}
# 此处访问地址为/home/dist2/dist2
location /dist2 {
root /home/dist2/;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
-----其它示例
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com:8080;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
server backup2.example.com:8080 backup;
}
------------------------------logs下面的nginx pid被删除的解决办法-------------------------------------------
查询nginx进程号并写入logs下的pid文件
ps -ef | grep nginx
-- 在logs下创建文件
touch nginx.pid
-- 写入文件
echo "34222" > nginx.pid
-- 重启服务:
./nginx -s reload
在docker里面安装nginx配置起来个人觉得挺麻烦,所以一般情况下选择提前下载好安装包直接在linux下安装的方式,文章仅供参考,具体安装方式也可根据具体情况而定。