nginx部署静态项目

nginx部署静态项目

一、安装nginx

1.安装nginx官方源

centos默认没有nginx官方安装源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2.在线安装nginx

yum install -y nginx

默认安装到/etc/nginx目录下

二、部署项目

1.进入到conf.d下,更改默认的default.conf 为oa.conf

2.更改配置oa.conf配置文件

vi oa.conf

2.1在文件头部添加:

upstream www.oa.com {

server 10.196.130.114:8090 weight=10 max_fails=2 fail_timeout=30s;

server 10.196.130.115:8090 weight=10 max_fails=2 fail_timeout=30s;

}

2.2 修改server_name

server_name www.oa.com;

2.3 注释掉location中root 和index

location / {

# root /usr/share/nginx/html;

# index index.html index.htm;

proxy_pass http://www.oa.com;

}

2.4 在location中添加代理

proxy_pass http://www.oa.com;

2.5 打开日志文件,修改日志文件名称

access_log /var/log/nginx/oa.access.log main;

三、启动nginx

1.在任意目录输入:nginx,如果没有报错,则启动成功

2.windows本地hosts文件中添加 nginx的ip 和域名

hosts路径:C:\Windows\System32\drivers\etc

注意:先选中文件,右键属性,去掉只读属性,才能编辑

用notepad++ 打开hosts文件,在末尾添加nginx服务器的ip 和对应的项目

10.196.130.116 www.oa.com

3.检查在windows中是否可以访问

输入网址:http://www.oa.com/TestOA

如果不能访问,请关闭防火墙

多项目部署在一台nginx,步骤一样,需要重启nginx

nginx -s reload 重启nginx

nginx -s stop 停止nginx

4.nginx查看项目存放日志路径

cd /etc/nginx/conf.d/

cat oa.conf

查看项目配置的访问日志路径:

posted @ 2023-06-27 09:52  常疯大虾  阅读(132)  评论(0编辑  收藏  举报