Windows 环境下安装和使用 nginx

1. 首先下载 nginx

下载地址:http://nginx.org/en/download.html

2. 将下载后的压缩包解压

在这里插入图片描述

3. 进入命令行启动 nginx

进入 cmd 命令行,进入到 nginx 的目录

启动 nginx.exe

在这里插入图片描述

打开任务管理发发现有 nginx.exe(32位)的进程

在这里插入图片描述

4. 配置 nginx.conf 文件

用 notepad++ 打开 nginx-1.10.2/conf/nginx.conf 文件

在 95 行处机上 include vhost/*.host;

在这里插入图片描述

5. 创建一个域名配置文件

在 nginx-1.10.2/conf 中创建一个 txt 文件

改名为 img.yuu.com.conf 后缀是.conf

在这里插入图片描述

用 notepad++ 打开配置如下

server {
    listen 80;
    autoindex off;
    server_name img.yyh.com;
    access_log c:/access.log combined;
    index index.html index.htm index.jsp index.php;
    #error_page 404 /404.html;
    if ( $query_string ~* ".*[\;'\<\>].*" ){
        return 404;
    }

    location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
        deny all;
    }

    location / {
        root E:\ftpfile\img;
        add_header Access-Control-Allow-Origin *;
    }
}

6. 配置 host 文件

打开 windos -> System32 -> dirvers -> hosts

在后面加上一句

127.0.0.1 img.yyh.com

7. 重启 nginx

在这里插入图片描述

8. 浏览器访问

浏览器访问 img.yuu.com/test.jpg

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37581282/article/details/83178555