nginx服务器部署

nginx(“engine x”)是一个高性能的HTTP和反向代理服务器。
 
  • 安装nginx
    • Linux下  sudo apt-get install nginx   
    • windows下 下载 nginx,然后安装
  • 配置nginx
    • Linux的配置目录通常在  /ect/nginx/  ,Windows的配置目录默认在  安装包路径/conf/  
    • 在配置目录下新建一个文件夹  sites-enabled ,存放自己配置的文件  nginx_sample.conf  。文件夹和文件都可自行命名
    •   nginx.conf  文件中的最外层大括号内末尾添加  include sites-enabled/nginx_sample.conf;  
  • 启动nginx
    • Linux下  sudo service nginx start  
    • Windows下,进入安装目录 start  ./nginx exe  
  •   nginx_sample.conf  文件配置
             server {
                    # listen port
                    listen 8011;
 
                    # host name or ip
                    server_name 127.0.0.1 test.sample.com;
 
                    # project root
                    root E:/webpack;
 
                    # log file path
                    access_log logs/access.log;
                    error_log logs/error.log;
 
                    # file router
                    location ~* .(html|js|css|png|jpg|jpeg|gif|ico){
                        add_header Cache-Control max-age=86400;
                    }
                    location ~* .json{
                        add_header Cache-Control max-age=86400;
                        add_header Content-Type "application/json; charset=UTF-8";
                    }
                }
  • 启动服务
    • 输入  http://127.0.0.1:8001/your_file  或者  http://test.sample.com:8011/your_file  即可访问对应的文件(域名访问需要配置hosts)
  • Windows下其他命令
    • 重启nginx服务  . ginx.exe --s reload  
    • 检查  nginx.conf  是否有错  . ginx.exe -t  
原文地址:https://www.cnblogs.com/my93/p/5691973.html