Windows下的Nginx配置

:D

首先是下载 此处以 1.8做实验
[url]http://nginx.org/download/nginx-1.8.0.zip[/url]

启动方式

绿色文件,无须安装,直接即可启动。

3种启动途径,其实都类似:

一、双击nginx.exe图标,可见黑窗口一闪而过,启动完毕。

二、命令行到nginx目录,输入nginx启动。(注,此方式命令行窗口无任何提示,且被锁定)

三、命令行到nginx目录,输入start nginx启动,此方式不锁定


nginx -s stop // 停止nginx
nginx -s reload // 重新加载配置文件
nginx -s quit // 退出nginx

启动后,默认情况下(无修改配置),可见到有两个nginx的进程,一个是[color=brown]master process[/color],一个是[color=olive]worker processes[/color]。


默认nginx部署了些静态内容,我们可通过它测试nginx是否在工作。

默认的配置文件(NGINX_HOME/conf/nginx.conf)如下


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

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
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;
# }
#}

}



通过观察配置文件的非注释项(参考Nginx配置文件nginx.conf中文详解),大概可知:

1、启动了1个worker processes

2、worker_connections,最大并发数为1024

3、include mime.types,引入mime.types文件所声明的文件扩展名与文件类型映射

4、application/octet-stream,默认使用application/octet-stream

5、sendfile,开启高效文件传输模式

6、监听本机“localhost”的80端口

7、映射目录为“当前目录的html目录”

8、出现500、502、503、504错误,则映射到50x.html



浏览地址http://localhost,即可访问其默认页面,即映射到NGINX_HOME/html/index.html

其他静态内容,如html、图片,可自行添加测试。



日志
日志默认位于NGINX_HOME/logs/,可见:

1、access.log,访问日志

2、error.log,异常日志

3、nginx.pid,进程(仅在启动nginx后才有此日志)


异常问题汇总:
[list]
[*]怎么都无法启动 nginx ?
[*]查看默认配置的80端口是否被iis占用?
[*]查看配置文件中的相关目录是否正确?
[*]查看配置文件...反正问题就出在配置文件.
[/list]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Windows配置Nginx的SSL证书,你可以按照以下步骤进行操作: 1. 获取SSL证书: 首先,你需要从证书颁发机构(CA)获取有效的SSL证书。这通常涉及到购买证书或使用免费的证书颁发机构(如Let's Encrypt)来获取证书。 2. 安装SSL证书: 将获取的SSL证书文件(通常包括.pem或.crt文件)保存到你的Windows计算机的某个位置,比如C:\ssl目录下。 3. 配置Nginx: 打开Nginx配置文件(通常是nginx.conf),找到与SSL相关的配置部分。 ``` server { listen 443 ssl; server_name yourdomain.com; ssl_certificate C:/ssl/your_certificate.crt; ssl_certificate_key C:/ssl/your_private_key.key; # 其他 SSL 配置... } ``` 在以上示例中,你需要将`yourdomain.com`替换为你的域名,并将`C:/ssl/your_certificate.crt`和`C:/ssl/your_private_key.key`替换为你保存证书的路径和文件名。 4. 重启Nginx: 保存配置文件后,重新启动Nginx服务器以使更改生效。 如果你使用的是Windows服务来运行Nginx,则可以通过以下命令重启服务: ``` net stop nginx net start nginx ``` 如果你是直接运行Nginx可执行文件,则需要关闭当前运行的Nginx进程,并重新启动Nginx。 现在,你的Nginx服务器应该已成功配置SSL证书,可以通过HTTPS访问你的网站了。请确保你的域名已正确解析到你的服务器IP地址,并且服务器的防火墙已打开相应的端口(通常是443)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值