Nginx配置

配置host

C:\Windows\System32\drivers\etc\hosts

用nginx等做代理转发到本机时最好通过host配置目的地址为127.0.0.1

配置conf

在主配置文件nginx.conf下引入其他conf

http {
    ... ...

    include vhost/*.conf;

    ... ...
}

1    在vhost/image.imooc.com.conf文件里,进行文件服务器配置,转发到目录上

server { 
    listen 80; 
    autoindex off; 
    server_name image.imooc.com; 
    access_log e:/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 *; 
    } 
}

参数解释

autoindex:是否自动创建索引,若设置off,直接输入域名则会报403错误,但是仍能通过URL访问里面的资源。

2    配置tomcat服务器的反向代理,转发到HTTP的IP地址和端口上

server { 
    listen 80; 
    autoindex on; 
    server_name tomcat.imooc.com; 
    access_log e:/access.log combined; 
    index index.html index.htm index.jsp index.php; 
    
    #error_page 404 /404.html; 
    if ( $query_string ~* ".*[\;'\<\>].*" ){ 
        return 404; 
    } 
    location / { 
        proxy_pass http://127.0.0.1:8080; 
        add_header Access-Control-Allow-Origin *; 
    } 
}

nginx命令

测试配置文件

nginx.exe -t

reload配置文件

nginx.exe -s reload

启动nginx

nginx.exe

 

转载于:https://my.oschina.net/u/3960535/blog/2248533

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值