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
直接修改之