07 Win10下Nginx的安装与使用

linux版本的参考文档:nginx配置

1 安装

Nginx官网:http://nginx.org/

下载	
nginx/Windows-1.24.0 

解压Nginx压缩包

在nginx的配置文件是conf目录下的nginx.conf,默认配置的nginx监听的端口为80,如果本地电脑的80端口有被占用,如果本地80端口已经被使用则修改成其他端口

查看80端口是否被占用的命令是
netstat -ano | findstr 0.0.0.0:80 
netstat -ano | findstr "80"

2 nginx命令

cmd命令窗口,然后切换到nginx目录下

运行
nginx
或者 
start nginx

停止
nginx -s stop 
或者
nginx -s quit
或者
taskkill /f /t /im nginx.exe

# 检查配置文件是否正确
nginx -t 
# 可以看到编译选项
nginx -V
#重启Nginx
nginx -s reload
#关闭Nginx
nginx -s stop
#优雅停止服务
nginx -s quit

3 nginx配置

默认配置
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;
    #    }
    #}

}

配置成反向代理

#反向代理配置
  location /itcast/ {
             proxy_pass http://127.0.0.1:12345;
             proxy_set_header X-real-ip $remote_addr;
             proxy_set_header Host $http_host;
         }
#使用虚拟目录时候控制器正常,但是视图中的js,css,路径不太对
location /proxy {
			proxy_pass http://localhost:7000;	
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			rewrite "^/proxy/(.*)$" /$1 break;					           
        }	
		
		location /bieming {
			alias  html/bieming/;
            index  index.html index.htm;
            
        }	
关闭版本Header信息头Server的版本
#gzip  on;
server_tokens off;

你可能感兴趣的:(nginx,运维)