nginx常用命令

1.测试配置文件:nginx -t

2.启动命令:nginx

3.停止命令:nginx -s stop或nginx -s quit

4.重启命令:nginx -s reload

5.查看进程命令:ps -ef |grep nginx

虚拟域名配置及测试验证:

配置步骤:

1.编辑nginx.conf

2.增加include vhost/*.conf

vhost配置文件解析:

server { 
    listen 80; 
    autoindex on; 
    server_name tomcat.imooc.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 / { 
        proxy_pass http://127.0.0.1:8080; 
        add_header Access-Control-Allow-Origin *; 
    } 
}

listen 80:监听80端口

autoindex on:是否自动创建首页索引目录

server_name tomcat.imooc.com:二级域名,当nginx接到这种请求,会通过proxy_pass,将这个域名请求转移到http://127.0.0.1:8080这个实际域名

proxy_pass:转移到的真实域名,这里也可以用root + 本地存放地址目录。

ngnix本地的注意事项:

1.可以配置域名转发,但一定要配置host(如果不配置host,用的域名就是真实域名,不会生效),并且使host生效之后才可以,设置完成之后要重启浏览器。

 配置host步骤:

  1)进入C:WindowsSystem32driversetc

  2)用记事本打开hosts文件

  3)添加好对应的域名及ip

原文地址:https://www.cnblogs.com/cing/p/8358775.html