Linux下安装Nginx

① 、安装nginx依赖:
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel
② 、解压nginx安装包:
tar –zxvf 安装包名称
③ 、移动解压后的文件夹:
mv 解压后的文件夹  新目录(新名字不能叫nginx)
mv nginx-1.16.0 /opt/mynginx
④ 、进入解压目录,执行编译及安装:
./configure –prefix=编译目录(./configure --prefix=/opt/nginx)
make
make install
⑤ 、启动
进入安装目录(生成的Nginx目录 ),sbin目录下的nginx即为启动脚本。
./nginx
⑥ 、通过80端口访问。
注意:如果不能访问,则关闭防火墙看是否能够出现Nginx界面,如果可以,则去/etc/sysconfig/iptables里面添加80端口,再执行service iptables save 后再开启:service iptables start
 
关闭Nginx,在Nginx/sbin目录下执行 ./nginx -s stop
:set nu 显示行号
 
修改/nginx/conf/nginx.conf配置信息:
 1 upstream test.com {
 2         server 127.0.0.1:8080;
 3 server 127.0.0.1:18080 ; #这个是配置的第二个Tomcat
 4    }
 5     server {
 6         listen       80;
 7         server_name  localhost;
 8  
 9         #location / {
10          #   root   html;
11           #  index  index.html index.htm;
12        # }
13 
14         location ~ .*\.(html|js|css|ico|jpg|jpeg|png|JPG|JPEG|PNG|eot|svg|ttf|woff) {
15             root html;
16         }
17   location ~ .*$ {#没有后缀的请求
18     proxy_pass http://test.com;#指定负载均衡的方式跟服务器
19               proxy_redirect default;
20         }
知识兔
在Nginx下访问Tomcat的静态资源:
通过ip地址+请求,直接访问项目的静态资源,在项目的静态页面的url中,必须加上项目名,这样,当通过Nginx访问项目的静态资源时,则就会加上项目名了
计算机