nginx搭建

nginx搭建

1.确认安装环境

在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel

安装命令:

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

2.下载nginx

下载地址:https://nginx.org/download/,移动到/usr/local/下。

3.编译

## 解压
tar -zxvf nginx-1.12.2.tar.gz

##进入nginx目录
cd nginx-1.12.2

## 配置
./configure --prefix=/usr/local/nginx  --with-http_stub_status_module --with-http_gzip_static_module --with-stream

# make
make&make install

4.测试是否安装成功

# cd到刚才配置的安装目录/usr/loca/nginx/
./sbin/nginx -t

输出以下则安装成功

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

5.启动nginx

cd /usr/local/nginx/sbin
#启动nginx
./nginx 

可能会输出:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

说明服务器的80端口已经被占用了,使用查看端口占用命令:netstat -anp |grep 80

发现进程55406的java应用占用了

tcp6       0      0 :::80                   :::*                    LISTEN      55406/java

使用ps -ef | grep 55406查看具体是哪个应用

root      47479  43550  0 10:46 pts/1    00:00:00 grep --color=auto 55406
root      55406      1  0 Jan26 ?        00:14:15 java -jar login-server-1.0-SNAPSHOT.jar

原来是登录服务器占用了,待会直接把他代理进来算了,直接停之,再次重新启动nginx

启动成功后在浏览器输入ip地址,我的是http://192.168.10.15/,能看到logo就算安装成功了

5.修改配置文件

咱们的配置文件路径是/usr/local/nginx/conf/nginx.conf

直接修改之

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值