Nginx

https://nginx.org/en/download.html

停止

nginx -s stop

启动

start nginx.exe

重载配置

nginx -s reload

重新启动(不会重载配置)

nginx -s reopen

创建文件报错 nginx: [error] CreateFile() "

强制结束重来

关闭日志

server {
		access_log off;

端口转发

找到配置文件 C:\nginx\conf\nginx.conf
在server下添加新的路由,添加后刷新或重启
server是个item可以加多个server

location / {
		root   html;
		index  index.html index.htm;
}
	
location /test/ {
		proxy_pass http://127.0.0.1:10086/test/; #建议名字与控制器对应,注意后方的斜杠
		
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

aspcore可以通过注入IHttpContextAccessor获得真实ip
Console.WriteLine(_context.HttpContext.Request.Headers["X-Real-IP"]);

部署SSL


将nginx配置443的解开注释,或者按照阿里云的帮助填写,下载的文件可以直接改名cert.key和cer.pem放在conf目录
为了路由只设置一遍 并且80 443共享配置,直接将443里面的内容复制到80下面也行(除了路由部分)

server {
        listen       443 ssl;
        server_name  tiantiankaixin.life;

        ssl_certificate      cert.pem;
        ssl_certificate_key  cert.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
		#表示使用的加密套件的类型。
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #表示使用的TLS协议的类型。
		ssl_prefer_server_ciphers on;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
posted @ 2021-11-18 12:58  trykle  阅读(22)  评论(0)    收藏  举报