[笔记]Nginx使用及Windows/Linux部署

简介: [笔记]Nginx使用及Windows/Linux部署

Windows

使用方式

启动

nginx.exe

配置转发

端口转发

http 80->8080

进入conf

修改 nginx.conf

如果配置http的

找80端口 解开注释

server {
        listen       80;
        server_name  localhost;# 服务名
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass https://127.0.0.1:8080;# 转发地址 可以是ip+端口
        }

https 443->8080

进入conf

修改 nginx.conf

如果配置https的

找443端口 解开注释

# HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  localhost;
        ssl_certificate      D:\tools\ngnix-1.12.2\nginx-1.12.2\ssl_aliyun\5115589_www.shiver.fun.pfx;
        ssl_certificate_key  D:\tools\ngnix-1.12.2\nginx-1.12.2\ssl_aliyun\pfx-password.txt;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass https://book_pool;
        }

注意:

PFX证书是window下面的证书,所以你Linux证书需要使用这个证书,我们需要把.PFX证书转换一下。我这里就转换成crt格式的了。

ssl_certificate_key需要证书的公钥

ssl_certificate需要.cert文件

都需要openssl生成

Nginx如何使用.PFX证书

关于解决nginx ssl问题处理

地址转发

常用命令

ngnix -s reload 
ngnix -s stop # 常常没用 需要手动 tasklist 然后 taskkill /pid /f
ngnix  #启动

Linux

nginx安装教程

完毕后

/usr/local/nginx

sbin里面有编译好的nginx

conf配置

/usr/local/nginx/nginx-1.9.9

objs里面有编译好的nginx

conf配置

记Nginx跨域问题

https://segmentfault.com/a/1190000020179829?utm_source=tag-newest

https://www.jianshu.com/p/520021853827

nginx方案

https://blog.csdn.net/zanpengfei/article/details/86605837

失败

https://cloud.tencent.com/developer/article/1648860

失败

后端方案

package team.shiver.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import team.shiver.handler.AuthenticationInterceptor;
@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**");    // 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录
    }
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }
    //跨域处理
    @Override
    public void addCorsMappings(CorsRegistry corsRegistry){
        /**
         * 所有请求都允许跨域,使用这种配置就不需要
         * 在interceptor中配置header了
         */
        corsRegistry.addMapping("/**").
                allowedOrigins("*"). //允许跨域的域名,可以用*表示允许任何域名使用
                allowedMethods("*"). //允许任何方法(post、get等)
                allowedHeaders("*"). //允许任何请求头
                allowCredentials(true). //带上cookie信息
                exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L); //maxAge(3600)表明在3600秒内,不需要再发送预检验请求,可以缓存该结果
    }
}

可行

Nginx使用场景

1.代理转发

常见问题

1.访问网站某些资源网站提示 net::ERR_CONTENT_LENGTH_MISMATCH 200 (OK)

原因

查看nginx 错误日记 tail -f nginx/logs/error.log,显示 nginx/proxy_temp/ 目录 无权限。

解决方案

chmod -R 777 nginx/proxy_temp/
相关文章
|
应用服务中间件 网络安全 nginx
手把手教你使用 Docker 部署 Nginx 教程
本文详解Nginx核心功能与Docker部署优势,涵盖镜像拉取、容器化部署(快速、挂载、Compose)、HTTPS配置及常见问题处理,助力高效搭建稳定Web服务。
4924 4
|
安全 Linux 生物认证
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
785 0
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
|
安全 Linux 生物认证
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
758 17
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
734 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
1467 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
应用服务中间件 Linux nginx
在虚拟机Docker环境下部署Nginx的步骤。
以上就是在Docker环境下部署Nginx的步骤。需要注意,Docker和Nginix都有很多高级用法和细节需要掌握,以上只是一个基础入门级别的教程。如果你想要更深入地学习和使用它们,请参考官方文档或者其他专业书籍。
654 5
|
Linux 虚拟化 iOS开发
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
2761 0
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
|
Linux iOS开发 计算机视觉
GIMP 3.0.6 (Linux, macOS, Windows) 发布 - 免费开源图像编辑器
GIMP 3.0.6 (Linux, macOS, Windows) 发布 - 免费开源图像编辑器
862 0
|
Linux
《循序渐进LINUX》笔记
基础知识、服务器搭建、系统管理、性能调优、集群应用 1、swap物理内存两倍 2、根分区5G 3、/boot 100M 4、查看系统硬件信息: cat /proc/meminfo cat /proc/cpuinfo 查看磁盘信息: fd...
1573 0
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
1237 1
二、Linux文本处理与文件操作核心命令