windows中安装Nginx

1.进入Nginx官网下载

2.选怎一个稳定版本,下载

3.解压D:\nginx-1.10.3

点击nginx.exe Nginx就行运行了。

查看进程的命令:

tasklist /fi "imagename eq nginx.exe"

停止Nginx

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

 

使用:http://localhost

 

4.常用的配置

D:\nginx-1.10.3\conf\nginx.conf



#user  root;
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;
    
    upstream myproject {   
        #ip_hash;
        #weigth参数表示权值,权值越高被分配到的几率越大。
        #weight 是权重,数字越大,优先级越高!max_fails 为最大失效次数!fail_timeout 为超时时间!
        server xxxxxx:8099 weight=10;
     }


    server {
        listen       8141;
        server_name  localhost 136.64.68.42 qc.tj.189.cn;
        client_max_body_size     10m;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        root   /home/chnweb/eshop/application/bjteleApp;
                index  login/login.html;
        #index  partner/index.html;

                rewrite "^[/]?$" "/index.html" last;

        proxy_set_header  Host  $host;
        proxy_set_header  X-Forwarxded-For  $remote_addr;

        proxy_pass http://myproject;
        }
        
        location ~ .*\.(html|css|js|gif|jpg|jpeg|png|json|ico|tff)$ {
                 root  /home/chnweb/eshop/application/bjteleApp;
                 index login/login.html;  
                    expires 2h;
                 #index  partner/index.html;                
        }
        location ^~ /tmp/ { #b.配置本地图片路径(图片存在d盘:portal/file文件夹下,注意前后的“/”不可省略),完整访问地址为第http://localhost/portal/file/xxxxx.jpg

            root /home/chnweb/eshop/qrcodePicture/;   #a.设置nginx根目录为d盘。
        }
        location ^~ /upload/image/ { #b.配置本地图片路径(图片存在d盘:portal/file文件夹下,注意前后的“/”不可省略),完整访问地址为第http://localhost/portal/file/xxxxx.jpg

            root  /home/chnweb/eshop/apache-tomcat-7.0.82/webapps/ROOT/;   #a.设置nginx根目录为d盘。
        }

          location /index/{
              root   /home/chnweb/eshop/application/bjteleApp/login;
              index login.html;

            }

        location /favicon.ico {
              log_not_found off;
               access_log off;
           }               

        #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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代理怎么做? 好的,我明白了。以下是安装Nginx并配置反向代理的步骤: 1. 首先下载NginxWindows版本,可以从官网 https://nginx.org/en/download.html 下载稳定版本。 2. 将下载好的Nginx压缩包解压到一个目录下,例如解压到D:\nginx目录下。 3. 打开cmd命令行窗口,进入到D:\nginx目录下的nginx.exe所在的目录。 4. 输入命令“nginx -t”,检查Nginx配置文件是否正确,如果出现“nginx: configuration file D:\nginx\conf\nginx.conf test is successful”则说明配置正确。 5. 配置反向代理,找到D:\nginx\conf\nginx.conf文件,并将以下代码添加到http{}标签内: ``` server { listen 80; server_name localhost; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ``` 其,listen表示监听端口,server_name表示服务器名字,location /表示请求的URL,proxy_pass表示转发到的服务地址,$host表示主机名,$remote_addr表示客户端IP,$proxy_add_x_forwarded_for表示客户端IP地址。 6. 保存配置文件并重启Nginx服务,可以使用命令“nginx -s reload”重启Nginx。 7. 验证反向代理是否生效,可以在浏览器访问http://localhost,如果能够正常展示代理的服务,则说明反向代理配置成功。 希望以上步骤能够帮助你成功安装Nginx并配置反向代理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值