[笔记]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/
相关文章
|
1月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025080401 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025080401 (Linux, Windows) - 专业渗透测试框架
63 0
|
28天前
|
安全 Linux iOS开发
Tenable Nessus 10.9.3 (macOS, Linux, Windows) - 漏洞评估解决方案
Tenable Nessus 10.9.3 (macOS, Linux, Windows) - 漏洞评估解决方案
168 0
Tenable Nessus 10.9.3 (macOS, Linux, Windows) - 漏洞评估解决方案
|
28天前
|
安全 Linux 生物认证
Nexpose 8.18.0 for Linux & Windows - 漏洞扫描
Nexpose 8.18.0 for Linux & Windows - 漏洞扫描
43 0
Nexpose 8.18.0 for Linux & Windows - 漏洞扫描
|
30天前
|
安全 Linux iOS开发
SonarQube Server 2025 Release 4.2 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
SonarQube Server 2025 Release 4.2 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
108 0
SonarQube Server 2025 Release 4.2 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
|
1月前
|
NoSQL IDE MongoDB
Studio 3T 2025.14 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.14 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
114 0
Studio 3T 2025.14 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
1月前
|
编解码 Ubuntu Linux
时隔半年,Linux 性能重新超越 Windows 11
用户可以访问 OpenBenchmarking.org 页面查看 Windows 和 Linux 之间所有 103 项基准测试的完整结果。
52 0
|
1月前
|
Ubuntu Linux Shell
手把手教你安装适用于Linux的Windows子系统——Ubuntu
重启完成,你看看重新打开Ubuntu是不是发生了变化,等待几分钟,系统配置完成,根据提示设置用户名和密码即可
|
1月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-2025073001 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025073001 (Linux, Windows) - 专业渗透测试框架
88 0
|
2月前
|
NoSQL IDE MongoDB
Studio 3T 2025.13 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.13 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
116 0