@liruiyi962464
2025-01-21T17:17:08.000000Z
字数 4892
阅读 72
windows部署
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 9527;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root .\html\dist;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
下载地址:https://github.com/winsw/winsw/releas
sample-minimal.xml以及WinSW-x64.exe
- 1:将下载的两个文件放到 nginx 的安装目录下,并且将其重命名为 nginx-service.exe、nginx-service.xml。
- 2:在 nginx 安装目录下新建服务日志文件夹 server-logs 文件夹,存放nginx服务相关日志。
- 3:修改 nginx-service.xml 文件,写入配置信息,就可将nginx注册为Windows服务
下载地址:https://github.com/winsw/winsw/releas
sample-minimal.xml以及WinSW-x64.exe
- 1:将下载的两个文件放到 nginx 的安装目录下,并且将其重命名为 nginx-service.exe、nginx-service.xml。
- 2:在 nginx 安装目录下新建服务日志文件夹 server-logs 文件夹,存放nginx服务相关日志。
- 3:修改 nginx-service.xml 文件,写入配置信息,就可将nginx注册为Windows服务
<!-- nginx-service.xml -->
<service>
<!-- 服务的唯一标识符,用于系统内部识别 -->
<id>nginx</id>
<!-- 服务显示名称,通常出现在服务列表中 -->
<name>nginx</name>
<!-- 服务的描述信息,提供关于服务功能的简短说明 -->
<description>这是一个基于Nginx的服务。</description>
<!-- 日志文件存放路径,指定Nginx将日志写入的具体位置 -->
<logpath>D:\fangzhen\server-logs\</logpath>
<!-- 日志模式,这里设置为"roll"意味着当达到一定大小时,日志文件会滚动更新 -->
<logmode>roll</logmode>
<!-- 启动服务时执行的命令或程序路径 -->
<executable>D:\fangzhen\nginx.exe</executable>
<!-- 停止服务时执行的命令或程序路径 -->
<stopexecutable>D:\fangzhen\nginx.exe -s stop</stopexecutable>
</service>
- 4:start.bat文件,一键安装nginx服务【以管理员身份运行】
@echo off
cd /d D:\fangzhen
nginx-service.exe install
sc config nginx start= auto
sc start nginx
echo Nginx服务已安装并已启动。
pause
- 5:stop.bat文件,一键删除nginx服务【以管理员身份运行】
@echo off
sc stop nginx
sc delete nginx
echo Nginx服务已删除。
pause
<!--
MIT License
Copyright (c) 2008-2020 Kohsuke Kawaguchi, Sun Microsystems, Inc., CloudBees,
Inc., Oleg Nenashev and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!--
This is an example of a minimal Windows Service Wrapper configuration, which includes only mandatory options.
This configuration file should be placed near the WinSW executable, the name should be the same.
E.g. for myapp.exe the configuration file name should be myapp.xml
You can find more information about the configuration options here: https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md
Full example: https://github.com/kohsuke/winsw/blob/master/examples/sample-allOptions.xml
-->
<service>
<!-- 服务的唯一标识符,用于系统内部识别 -->
<id>nginx</id>
<!-- 服务显示名称,通常出现在服务列表中 -->
<name>nginx</name>
<!-- 服务的描述信息,提供关于服务功能的简短说明 -->
<description>这是一个基于Nginx的服务。</description>
<!-- 日志文件存放路径,指定Nginx将日志写入的具体位置 -->
<logpath>D:\fangzhen\server-logs\</logpath>
<!-- 日志模式,这里设置为"roll"意味着当达到一定大小时,日志文件会滚动更新 -->
<logmode>roll</logmode>
<!-- 启动服务时执行的命令或程序路径 -->
<executable>D:\fangzhen\nginx.exe</executable>
<!-- 停止服务时执行的命令或程序路径 -->
<stopexecutable>D:\fangzhen\nginx.exe -s stop</stopexecutable>
</service>