0
点赞
收藏
分享

微信扫一扫

windows下配置并启动Nginx并做本地目录映射

王传学 2022-08-24 阅读 92


1、查看nginx进程

  tasklist /fi "imagename eq nginx.exe",如下显示:
映像名称                       PID 会话名              会话#       内存使用
========================= ======== ================ =========== ============
nginx.exe                     8944 Console                    1      5,128 K
nginx.exe                     6712 Console                    1      5,556 K

2、nginx常用命令

nginx -s stop 强制关闭 
nginx -s quit 安全关闭 
nginx -s reload 改变配置文件的时候,重启nginx工作进程,来时配置文件生效 
nginx -s reopen 打开日志文件

3、其它
  可以通过配置文件开启多个nginx工作进程,但同时只有其中一个nginx工作进程在工作,其他的阻塞等待。
  一个nginx工作进程最多同时可以处理1024个连接。
  nginx中需要共享内存的cache或者模块无法在windows下正常使用。
  不过,nginx官方正在改进,将来nginx会以服务的方式运行,使用 I/O completion ports代替select方法,使多个工作进程能并发工作。
  要使用nginx配合php-cgi使用,需要修改环境变量,否则,php-cgi运行一定次数就推出,需要重启,设置PHP_FCGI_MAX_REQUESTS这个变量为0即可。

  以上在win7上通过。 



4、直接贴出整个配置文件了,红色部分是重点:

#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 88;
server_name localhost;


#charset koi8-r;


#access_log logs/host.access.log main;


location / {
root html;
index index.html index.htm;
}
location /attached {
root /;
rewrite ^/image/(.*)$ /attached/$1 break; #这里很重要,rewrite就是真正的跳转规则使Nginx能访问目录不在nginx根目录下的文件夹
autoindex on; #启用目录索引功能
autoindex_exact_size off; #关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_localtime on; #开启以服务器本地时区显示文件修改日期!
}#location /attached 设置服务器拦截含有/attached 的请求,实际上范围根据实际情况确定精确度
image开头的根目录,后面的参数原封不动的添加过去,这样就实现了目录的映射,
  #使用上面的规则可以很方便的映射到本地指定的多个用于静态访问的目录
./nginx -s reload




#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;
# }
#}


}

举报

相关推荐

0 条评论