当前位置: 首页 > news >正文

最好的免费发布网站日照网站优化公司

最好的免费发布网站,日照网站优化公司,金融网站建设报价方案,自己的做网站项目里面有一个需求,就是需要用让nginx进程提供给系统管理一个start,stop和getPid方法,这样系统管理可以自动拉起来nginx,达到自动部署的目的。离线部署同样适用 这样一来,我就需要提供windows版本linux不同版本的nginx源码包&am…

项目里面有一个需求,就是需要用让nginx进程提供给系统管理一个start,stop和getPid方法,这样系统管理可以自动拉起来nginx,达到自动部署的目的。离线部署同样适用

这样一来,我就需要提供windows版本linux不同版本的nginx源码包,windows版本的好办,就直接从官网下载的,我下载的是nginx1.24.0的稳定版本的,linux版本的就需要自己编译源码包了,因为wget下载的nginx首先产物目录就很不一样,我需要就是跟windows差不多的目录结构,便于我写nginx.conf配置文件

window的产物目录如下

linux产物目录如下

linux的这个产物只需要编译一次,后面部署就直接拷贝这个就可以了,编译的过程如下:

官网下载nginx源码,新建一个文件夹叫Nginx

进入到源码目录 

./configure --prefix=新建的产物目录地址
make -j12
make install 

可能中间需要装 pcre库,wget 下载一下好了。

pcre是因为我的nginx配置需要用到正则,就是html下面有不同文件夹,每个文件夹是一个项目,部署的时候有多少个文件夹部署多少个项目。

这个过程比较曲折,首先nginx没有地方写日志是不会启动成功的,所以配置文件需要指定日志的生成位置,还有配置文件的启动位置,pid等

贴一份windows的配置文件:

worker_processes  1;
error_log  D:/code/system/run/nginx/logs/error.log error;
pid        D:/code/system/run/nginx/logs/nginx.pid;
events { worker_connections  1024; 
} 
http { include       mime.types; default_type  application/octet-stream; sendfile        on; keepalive_timeout  65; access_log D:/code/system/run/nginx/logs/access.log; map $_FilePath $_FilePathForUse { "" "index.html"; "/" "index.html";default $filePathFromRemote; }client_body_temp_path D:/code/system/run/nginx/temp/client_temp; proxy_temp_path D:/code/system/run/nginx/temp/proxy_temp; fastcgi_temp_path D:/code/system/run/nginx/temp/fastcgi_temp; uwsgi_temp_path D:/code/system/run/nginx/temp/uwsgi_temp;scgi_temp_path D:/code/system/run/nginx/temp/scgi_temp; server { listen 8090; location /{ gzip on; gzip_static on; root  D:/code/system/run/nginx/html/; add_header X-URI-Part1 $1; add_header X-URI-Part2 $2; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; set $module $1; set $filePathFromRemote $2; set $_FilePath "$filePathFromRemote"; } error_page 500 502 503 504 /50x.html; } server { listen 9000; location / {  root  D:/code/system/run; autoindex on;  add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With;  add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;  }  } 
} 

两个server是因为还用到了nginx做文件服务

linux版本的配置文件:

  worker_processes  1;error_log  ${ROOT_DIR}/run/nginx/logs/error.log error;pid         ${ROOT_DIR}/run/nginx/logs/nginx.pid;events {worker_connections  1024;}http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;access_log  ${ROOT_DIR}/run/nginx/logs/access.log; map $_FilePath $_FilePathForUse {"" "index.html";"/" "index.html";default $filePathFromRemote;}client_body_temp_path ${ROOT_DIR}/run/nginx/client_temp;proxy_temp_path ${ROOT_DIR}/run/nginx/proxy_temp;fastcgi_temp_path ${ROOT_DIR}/run/nginx/fastcgi_temp;uwsgi_temp_path ${ROOT_DIR}/run/nginx/uwsgi_temp;scgi_temp_path ${ROOT_DIR}/run/nginx/scgi_temp;server {listen 8090;server_name localhost;location ~ ^/([^/]+)(/?.*)$ {root  ${ROOT_DIR}/run/nginx/html/;add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Credentials' 'true';set $module $1;set $filePathFromRemote $2;set $_FilePath "$filePathFromRemote";}error_page 500 502 503 504 /50x.html;location = /50x.html {root ${ROOT_DIR}/run/nginx/html;}}server {listen 9000;server_name localhost;location / {root ${ROOT_DIR}/run;autoindex on;add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Headers X-Requested-With;add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;}}}

这两个配置文件的生成是通过脚本自动写入的,用到了各自系统的环境变量

下面就是启动程序了

start方法

#ifdef _WIN64cmd = fmt::format("{}/nginx/nginx -c {}/nginx/conf/nginx.conf -e {}/nginx/logs/error.log",根目录,根目录);#endif #ifdef __linux__cmd = fmt::format("{}/nginx/sbin/nginx -c {}/nginx/conf/nginx.conf -e {}/nginx/logs/error.log",根目录,根目录,根目录);#endif

大概就是通过命令行启动nginx进程,涉及到一些公司里面封装的底层方法,就不方便写了。。

stop方法同理

getPid方法比较复杂,nginx每次启动成功都会往nginx.pid文件写入一个进程号,需要把文件读出来然后返回出去,而且需要自己判断进程是不是存活,不能返回一个没有启动的进程出去。

启动成功之后浏览器输入当前机器的ip地址:8090就能访问到内容

系统管理界面可以管理nginx的启停

http://www.hkea.cn/news/933411/

相关文章:

  • 那个b2b网站可以做外贸武汉全网推广
  • 深圳css3网站开发多少钱如何策划一个营销方案
  • 织梦统计网站访问量代码网络营销公司如何建立
  • 外贸营销型网站建设今日最新重大新闻
  • 个性化定制网站长春网络推广优化
  • 合肥庐阳区疫情最新消息seo优化首页
  • h5网站制作接单最新中高风险地区名单
  • 北京市住房城乡建设委网站公司怎么在网上推广
  • 网站建设首页怎样插入视频百度指数在线查询小程序
  • 青州网站制作哪家好aso优化哪家好
  • wordpress做网站优点郑州网站seo优化
  • 宝安做棋牌网站建设找哪家公司好湖南长沙疫情最新消息
  • 四川专业网站建设中国十大企业培训机构排名
  • 怎么切页面做网站灰色词首页排名接单
  • 网站右侧浮动广告代码百度推广代理公司广州
  • 固原建站公司旺道seo推广系统怎么收费
  • 适合做外链的网站海外广告联盟平台推广
  • 建筑模板规格型号郑州厉害的seo顾问
  • ppt做书模板下载网站有哪些内容国际婚恋网站排名
  • 上海网站建设内容更新网络营销策划目的
  • 重庆市建设信息网站关键词查询网
  • 做哪种网站流量大怎么打广告宣传自己的产品
  • 免费表白网站制作seo网络优化推广
  • 网站建设中可能升级中国科技新闻网
  • 网站制作内容文案网站如何快速被百度收录
  • 淘宝淘宝网页版登录入口免费seo公司
  • 竹溪县县建设局网站短视频营销
  • 好的网站有哪些搜索引擎seo是什么意思
  • 做音乐网站赚钱吗做小程序的公司
  • 坪地网站建设域名流量查询工具