Nginx安装
Windows版
官方下载路径:http://nginx.org/en/download.html
1.下载
2.解压
3.运行
到nginx.exe目录下
4.浏览器访问测试是否运行,出现下面这个页面表示运行成功(默认端口是80)
Linux版
1.下载
2.上传到Linux服务器上
3.解压
tar -zxvf 压缩文件名.tar.gz
4.进入nginx配置
[root@VM-16-16-centos nginx-1.20.2]# ./configure
如果出现上面这种情况的话需要安装Nginx相关依赖
[root@VM-16-16-centos nginx-1.20.2]# yum -y install gcc openssl openssl-devel pcre-devel zlib zlib-devel
当再次执行./configure出现上图信息表示没问题了
接着在执行make
[root@VM-16-16-centos nginx-1.20.2]# make
再执行 [root@VM-16-16-centos nginx-1.20.2]# make install
再去执行whereis nginx查看
[root@VM-16-16-centos nginx-1.20.2]# whereis nginx
5.去启动Nginx
查看端口
#到Nginx目录
[root@VM-16-16-centos nginx]# ll
总用量 36
drwx------ 2 nobody root 4096 11月 30 15:52 client_body_temp
drwxr-xr-x 2 root root 4096 11月 30 15:46 conf
drwx------ 2 nobody root 4096 11月 30 15:52 fastcgi_temp
drwxr-xr-x 2 root root 4096 11月 30 15:46 html
drwxr-xr-x 2 root root 4096 11月 30 15:52 logs
drwx------ 2 nobody root 4096 11月 30 15:52 proxy_temp
drwxr-xr-x 2 root root 4096 11月 30 15:48 sbin
drwx------ 2 nobody root 4096 11月 30 15:52 scgi_temp
drwx------ 2 nobody root 4096 11月 30 15:52 uwsgi_temp
[root@VM-16-16-centos nginx]# cd conf/
[root@VM-16-16-centos conf]# ll
总用量 68
-rw-r--r-- 1 root root 1077 11月 30 15:46 fastcgi.conf
-rw-r--r-- 1 root root 1077 11月 30 15:48 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 11月 30 15:46 fastcgi_params
-rw-r--r-- 1 root root 1007 11月 30 15:48 fastcgi_params.default
-rw-r--r-- 1 root root 2837 11月 30 15:48 koi-utf
-rw-r--r-- 1 root root 2223 11月 30 15:48 koi-win
-rw-r--r-- 1 root root 5231 11月 30 15:46 mime.types
-rw-r--r-- 1 root root 5231 11月 30 15:48 mime.types.default
-rw-r--r-- 1 root root 2656 11月 30 15:46 nginx.conf
-rw-r--r-- 1 root root 2656 11月 30 15:48 nginx.conf.default
-rw-r--r-- 1 root root 636 11月 30 15:46 scgi_params
-rw-r--r-- 1 root root 636 11月 30 15:48 scgi_params.default
-rw-r--r-- 1 root root 664 11月 30 15:46 uwsgi_params
-rw-r--r-- 1 root root 664 11月 30 15:48 uwsgi_params.default
-rw-r--r-- 1 root root 3610 11月 30 15:48 win-utf
[root@VM-16-16-centos conf]# cat nginx.conf
执行cat nginx.conf后就可以发现
server {
listen 80; # 端口号
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
启动好后再去访问服务器默认是80端口
Nginx常用命令
cd /usr/local/nginx/sbin/
./nginx #启动
./nginx -s stop #停止
./nginx -s quit #安全退出
./nginx -s reload #重新加载配置文件
ps aux|grep nginx #查看nginx进程
简单配置操作
# 这下面中upstream mecxy {}、proxy_pass这两个是要自己添加进去的
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# 配置负载均衡
upstream mecxy {
# ip:端口号 权重
server 127.0.0.1:8081 weight=1;
server 127.0.0.1:8080 weight=1;
}
server {
listen 80; # 默认端口号
server_name localhost; # 设置主机域名
#设置虚拟主机的基本信息
location / {
root html;
index index.html index.htm;
proxy_pass http://mecxy; # 反向代理用的
}
}
}