Nginx安装和简单配置

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 1130 15:52 client_body_temp
drwxr-xr-x 2 root   root 4096 1130 15:46 conf
drwx------ 2 nobody root 4096 1130 15:52 fastcgi_temp
drwxr-xr-x 2 root   root 4096 1130 15:46 html
drwxr-xr-x 2 root   root 4096 1130 15:52 logs
drwx------ 2 nobody root 4096 1130 15:52 proxy_temp
drwxr-xr-x 2 root   root 4096 1130 15:48 sbin
drwx------ 2 nobody root 4096 1130 15:52 scgi_temp
drwx------ 2 nobody root 4096 1130 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 1130 15:46 fastcgi.conf
-rw-r--r-- 1 root root 1077 1130 15:48 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 1130 15:46 fastcgi_params
-rw-r--r-- 1 root root 1007 1130 15:48 fastcgi_params.default
-rw-r--r-- 1 root root 2837 1130 15:48 koi-utf
-rw-r--r-- 1 root root 2223 1130 15:48 koi-win
-rw-r--r-- 1 root root 5231 1130 15:46 mime.types
-rw-r--r-- 1 root root 5231 1130 15:48 mime.types.default
-rw-r--r-- 1 root root 2656 1130 15:46 nginx.conf
-rw-r--r-- 1 root root 2656 1130 15:48 nginx.conf.default
-rw-r--r-- 1 root root  636 1130 15:46 scgi_params
-rw-r--r-- 1 root root  636 1130 15:48 scgi_params.default
-rw-r--r-- 1 root root  664 1130 15:46 uwsgi_params
-rw-r--r-- 1 root root  664 1130 15:48 uwsgi_params.default
-rw-r--r-- 1 root root 3610 1130 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;  # 反向代理用的
        }

    }


}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是鱼染哟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值