Nginx配置同时支持http和https两种方式访问

这篇具有很好参考价值的文章主要介绍了Nginx配置同时支持http和https两种方式访问。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

http:
nginx 同时支持http和https,java,nginx,http,https
https:

Nginx的ssl模块安装

进入到目录的sbin目录下,输入

#注意这里是大写的V,小写的只显示版本号
./nginx -V  

如果出现 (configure arguments: --with-http_ssl_module), 则已安装(下面的步骤可以跳过,直接进行第五步)。

一般情况下都是不存在ssl模块的,接下来进入到你的解压缩后的nginx目录,注意这里不是nginx安装目录,是解压缩后的目录。

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

然后执行

make
#切记不要执行make install,否则会重新安装nginx

接下来使用新的nginx文件替换掉之前安装目录sbin下的nginx,注意这里的替换的时候可以先将之前的文件备份下,停掉nginx服务。

./nginx -s stop #停止nginx服务

#替换之前的nginx
cp /usr/nginx/objs/nginx /usr/local/nginx/sbin

成功之后,进入到nginx安装目录下,查看ssl时候成功

#注意这里是大写的V,小写的只显示版本号
./nginx -V  
#可以看到这里出现了configure arguments: --with-http_ssl_module   证明已经安装成功

nginx 同时支持http和https,java,nginx,http,https
nginx.conf文章来源地址https://www.toymoban.com/news/detail-537762.html


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

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
        	proxy_pass http://ip:端口/;
            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       80;
        listen       443 ssl;
        server_name  ip;
		 
		  location / {
        	proxy_pass http://ip:端口/;
        }

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

}

到了这里,关于Nginx配置同时支持http和https两种方式访问的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Nginx 一个端口同时支持 http 和 https协议【详细步骤】

    🚀 背景:使用 Nginx 1.24.0 代理前端及后端应用,假设称之为 A 系统。A 系统最初使用的是 http 协议,后来改成了 https 协议。 Nginx 配置 https 访问【图文教程】:Nginx 配置 https 访问 😭 问题:修改为 https 协议后,发现一些问题。即 依赖 A 的系统没有改成 https,导致报错 。 👉

    2024年01月25日
    浏览(36)
  • nginx支持一个端口访问多个前端项目(http以及https)

        最近做项目结构优化,前端项目都是部署在nginx上,想实现同一个端口可以访问多个前端项目.这样可以提高服务器的端口复用率,降低项目部署以及维护成本.根据平常的需求,用两台nginx服务器分别支持http、https同一端口访问不同项目。下面将配置方式以及相关注意事项做简

    2024年02月03日
    浏览(45)
  • nginx 同一个端口支持http和https配置

    原理:使用nginx的stream、 stream_ssl_preread模块 1.编译nginx 由于stream和stream_ssl_preread模块非默认引入,需要在编译安装nginx时引入;编译时添加配置参数 --with-stream --with-stream_ssl_preread_module ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-stre

    2024年02月10日
    浏览(32)
  • nginx的同一个端口配置支持http与https协议

    http://www.baidu.com:5000 https://www.baidu.com:5000 请求自定义端口的http 跟https,都一样的页面 vim /opt/lucky/nginx/conf/vhosts/baidu.conf

    2024年02月13日
    浏览(37)
  • Nginx配置https网站访问第三方节点的http资源

    https网站无法直接下载http网站的文件。解决思路有以下几种情况:1.两个网站都同时改为http或https。2.通过nginx转发。3.通过后端java代码获取对方网站的文件流然后把流返回给前端 本文介绍如果通过nginx转发访问http网站 配置规则一: 这样配置之后,本地网站比如是:访问htt

    2024年02月16日
    浏览(34)
  • kubernetes的ingress实现同时支持http和https

    生产环境中对外的服务一般需要配置https服务,使用ingress也可以很方面的添加https的证书。默认情况下,如果为该 Ingress 启用了 TLS,控制器会使用 308 永久重定向响应将 HTTP 客户端重定向到 HTTPS 端口 443。( Ingress 里配置了 https 证书的话,默认就一定会走 https)。即默认情况

    2024年02月15日
    浏览(35)
  • SpringBoot + Vue2项目打包部署到服务器后,使用Nginx配置SSL证书,配置访问HTTP协议转HTTPS协议

    配置nginx.conf文件,这个文件一般在/etc/nginx/...中,由于每个人的体质不一样,也有可能在别的路径里,自己找找... 证书存放位置,可自定义存放位置 两个文件 后端配置 把.pfx拷贝到resource下,然后配置一下yml

    2024年02月02日
    浏览(51)
  • 虚拟机上用docker + nginx跑前端并支持https和http

    情况是这样,我在虚拟机上,使用docker跑前端,需要这个前端支持https,原http的话自动跳转到https。另外,前端部署使用了负载均衡,即使用了3个docker跑前端:1个入口,另外2个是前端,指向了同一份网站代码。(有关前端部署负载均衡,详见拙作《使用docker部署多个nginx站点

    2024年02月12日
    浏览(31)
  • nginx配置https访问

    为什么需要使用HTTPS,因为HTTP不安全,当使用http进行消息传输时,可能会遭到黑客的劫持和篡改,如果采用https协议,那么数据在传输过程中是加密的,所以黑客无法窃取或者篡改数据报文信息,同时也避免网站传输时信息泄露。 实现https:需要使用ssl协议。 首先需要申请证

    2024年01月22日
    浏览(29)
  • Linux配置Nginx SSL支持Https配置教程

    继承上篇 Linux安装Nginx 执行: ./nginx -V 命令 如果有输出 --–with-http_ssl_module 则说明已安装好SSL模块 进入安装目录 /usr/local/nginx-1.22.1 执行安装命令: ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 执行编译命令: make 注意:make成功后不要执行 make insta

    2024年01月18日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包