系统相关
首页 > 系统相关> > Windos安装Nginx

Windos安装Nginx

作者:互联网

1、下载

链接:https://pan.baidu.com/s/13diesF95Wj9UK-JKRhsDWw 
提取码:92x7

或者打开nginx的官网:http://nginx.org/ ,下载最新的稳定版本。

2、安装

下载完成后,解压到你想要解压的文件路径中,我解压到了D盘中,并把文件名改为nginx;进入文件内,打开nginx.exe文件,会出现一个一闪而过的页面,然后打开任意一个浏览器,输入 localhost,出现下面的页面,则安装成功。

 

如果没有出现,则说明没有安装成功;通过cmd.exe来看nginx是否安装成功和错误所在。打开cmd后,输入D:(你的安装目录在哪输入哪个),再输入cd nginx,继续输入nginx,如果安装不成功就会反馈错误,我出现的错误是:[emery] blind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

也就是80端口被其他程序占用。

解决方法是:以管理员身份运行regedit打开键值:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP在右边找到Start这一项,将其改为0重启系统,System进程不会占用80端口。
nginx的配置文件是conf目录下的nginx.conf,默认配置的nginx监听的端口为80,如果80端口被占用可以修改为未被占用的端口即可
检查80端口是否被占用的命令是: netstat -ano | findstr 0.0.0.0:80 或 netstat -ano | findstr "80"

当我们修改了nginx的配置文件nginx.conf 后,执行命令 nginx -s reload 即可让改动生效

关闭nginx
如果使用cmd命令窗口启动nginx,关闭cmd窗口是不能结束nginx进程的,可使用两种方法关闭nginx

(1)输入nginx命令 nginx -s stop(快速停止nginx) 或 nginx -s quit(完整有序的停止nginx)

(2)使用taskkill taskkill /f /t /im nginx.exe

3、遇到的问题及解决方案:

Nginx代理导致请求头header中的信息丢失问题

方法一:不用下划线
把下划线_改成其他的,如sign_val改成sign-val

方法二:从根本解除nginx的限制
nginx默认request的header的那么中包含’_’时,会自动忽略掉。
解决方法是:在nginx里的nginx.conf配置文件中的http部分中添加如下配置:
underscores_in_headers on; (默认 underscores_in_headers 为off)

4、附上我的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;
    #设置允许发布内容为1024M
    client_max_body_size 1024M;
    client_body_buffer_size 256k;
    underscores_in_headers on;
    #gzip  on;
    #nginx+zuul实现负载均衡
    #upstream  server {
        #server    localhost:5012  weight=1; #zuul1 server
   # }

    server {
        listen       5011;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location /web {
            proxy_pass   http://localhost:5012;
	#proxy_pass   http://server;
        }
        location / {
            root   html;
            #index  index.html index.htm;
        }
        #location /static {
            #alias   D:/nginx/nginx-1.12.2/html/static;
        #}

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

}

 

标签:index,log,nginx,server,Nginx,html,location,Windos,安装
来源: https://blog.csdn.net/qq_31122833/article/details/105857598