Installation and simple configuration of nginx in Windows environment

Source: Internet
Author: User
Tags sendfile

Learn a little bit of programming every day PDF ebook, video tutorial free download: Http://www.shitanlife.com/code

I. Download and install Nginx

Go to nginx website to download

I choose nginx/windows-1.10.3 version here, download and extract it, the extracted path can not contain Chinese

After I unzip it, place the path as follows

Second, start running

Under current directory, press and hold shift+ right mouse button, select "Open Command Window Here", then enter start Nginx

At this point, you can enter the browser input access address, HTTP://127.0.0.1/or http://localhost/to access

Three, the configuration file explanation

The core configuration file is nginx.conf, which is located in the Conf directory, and in most cases we modify the configuration of the file.

The original configuration of the file is as follows:

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

  

Where # Represents a comment

Nginx Our main role is to do reverse proxy and load balancing, which I will focus on later on. It is also a Web server that can be used to host Web services, as we commonly use for Apache, Tomcat, and IIS.

This chapter introduces a few important parameters of the configuration file, followed by the Nginx deployment of PHP and Python project again to focus on, the Java project is usually tomcat+nginx at the same time to configure, Nginx used to do load balancing and processing static pages.

1, define the user and user group Nginx run

1 #user  nobody;

2, Nginx process number, recommended to set equal to the total number of CPU cores

1 worker_processes 1;

3. Global error log definition type, [Debug | info | notice | warn | error | crit]

12 #error_log logs/error.log notice;#error_log logs/error.log info;

4. Process files

1 #pid        logs/nginx.pid;

5, the working mode and the maximum number of connections: Worker_connections is the largest number of concurrent links for a single background worker process, and the total number of concurrent worker_processes and Worker_connections is the product of Max_ Clients = worker_processes * worker_connections

123 events {worker_connections 1024;}

6. Some configuration under HTTP and its significance

12345678 include mime.types; #文件扩展名与文件类型映射表default_type application/octet-stream#默认文件类型sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来 输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置 为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常 把这个改成off。autoindex on; #开启目录列表访问,合适下载服务器,默认关闭。tcp_nopush on; #防止网络阻塞tcp_nodelay on; #防止网络阻塞keepalive_timeout 120; #长连接超时时间,单位是秒gzipon; #开启gzip压缩输出

7, the server virtual host related configuration

We usually configure a variety of servers, the most configuration is these places

Like what:

123456789101112131415161718192021 http{ #虚拟主机1 server{  listen       80;   #监听端口,基于IP配置的时候变更此处,比如192.168.1.100:8080;  server_name  www.xdw.com;  #主机域名,实际项目发布的话,填公网上的域名,本地部署的话,可以在C:\Windows\System32\drivers\etc\hosts文件中添加IP和域名的映射  location / {      #映射解析,/代表根路径,此处解析还有正则表达式的解析方式,具体请参考http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#location     root   E:/xdw/0221;   #工程所在路径     index  index.html index.htm;  #首页(默认页)  } }  #虚拟主机2,可以同时配置多个虚拟主机 server{  listen       8080;  server_name  localhost;  location / {     root   D:/xiangmu/txym_web;     index  index.html index.htm;  } }}

See the configuration of this virtual host, I believe the configuration of Tomcat or Apache people are very familiar with the feeling. This concludes with an update of the configuration under Linux, the deployment of PHP and Python projects, reverse proxies and load balancing, and the deployment of Java projects with Tomcat.

Installation and simple configuration of nginx in Windows environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.