隐藏

nginx在windows下与IIS共用80端口及nginx的配置

发布:2022/3/10 17:52:53作者:管理员 来源:本站 浏览次数:1835

IIS共存,先停IIS服务,启动Nignx后,再启动IIS

1、服务下把下面服务先停掉

World Wide Web Publishing Service  停掉

2、执行以下命令:(cmd)
net stop http
Sc config http start= disabled


3、netstat -aon | findstr :80 查看80端口是否被占用


仍占用重启windows服务,80端口释放

4、重启后再查看,


没有占用则可以启动Nginx,如下成功启动Nginx后,再启用IIS服务

先执行(cmd) 一、 sc config http start=demand & net start http

再执行 二、World Wide Web Publishing Service  服务启动


1、目录下nginx   看版本
2、启动。打开cmd.exe,然后跳转到解压之后文件的目录下。然后输入:start nginx命令来启动nginx。

为了验证nginx是否启动,可输入下列命令验证:tasklist /fi "imagename eq nginx.exe"如果出现下图的信心,则说明启动成功。

 
4、停止。在cmd.exe中输入:nginx -s stop(正常停止)命令即可关闭nginx。此外命令:nginx -s quit表示快速停止。

5、修改完Nginx配置可以用 nginx -s reload重新加载


配置多个域名指向不同站点


#user  nobody;
worker_processes  8;

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

#pid        logs/nginx.pid;


events {
    worker_connections  4000;
}


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;

    proxy_set_header   Host             $host; 
    proxy_set_header   X-Real-IP        $remote_addr; 
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #服务器集群名称为Jq_one
    upstream Jq_one {
	server  11.91.194.95:8004;
	ip_hash; 
    }

    server {
        listen       80;
        listen 443 ssl;
        ssl_certificate      E://2020//HuoDongBaoMing//domaincertify//fullchain.crt;
        ssl_certificate_key  E://2020//HuoDongBaoMing//domaincertify//private.pem;


	ssl_protocols TLSv1.1 TLSv1.2;
	ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
	ssl_prefer_server_ciphers on;
	ssl_session_cache shared:SSL:10m;
	ssl_session_timeout 10m;


        server_name  hdbm.95.yy.com;

        #charset koi8-r;

        access_log  logs/access.log  main;

        location / {
            root   html;
            index  index.aspx index.html index.htm;
	    #指向集群名称为Jq_one
	    proxy_pass         http://Jq_one; 
	    #设置主机头和客户端真实地址,以便服务器获取客户端真实IP
	    proxy_set_header   Host             $host; 
	    proxy_set_header   X-Real-IP        $remote_addr; 
	    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        }
	#静态资源缓存设置
	location ~ \.(jpg|png|jpeg|bmp|gif|swf|css|js|ico|ttf|html|htm|txt)$
        { 
            expires 30d;
            root E:\2020\HuoDongBaoMing;#root:
            access_log  off;
            #break;
        }

	location ~ .* {
                        proxy_pass http://Jq_one;
                        proxy_set_header Host $host; 
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }




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


    }

server {

       listen       80;

       server_name  site1.95.nxzhly.com;

       location / {

                     proxy_pass http://11.91.194.95:8001/;

              }

    }
server {

       listen       80;

       server_name  site2.95.nxzhly.com;

       location / {

                     proxy_pass http://11.91.194.95:8002/;

              }

    }
server {

       listen       80;

       server_name  site3.95.nxzhly.com;

       location / {

                     proxy_pass http://11.91.194.95:8003/;

              }

    }


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

}
IIS配置如下图:


注意事项是IIS的域名绑定可以直接是域名,直接设置非80端口即可

2、内外网IP都要设置

Nginx 静态资源不能用汉字,站点要建成英文的,不然图片都不能显示


Nginx有更改时,直接进入Nginx目录,然后执行nginx -s reload