Centos Nginx SSL 配置

Nginx 配置 SSL

1.下载SSL证书

.crt 和 .key文件

2.创建和上传证书

bash 复制代码
mkdir -p /etc/nginx/cert
上传证书

3.nginx.conf配置

bash 复制代码
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    
    include /etc/nginx/conf.d/*.conf;
    
    server {
	listen 80;
        server_name baiduX.com www.baiduX.com;
        return 301 https://$server_name$request_uri;  
    }

    server {

 	listen 443 ssl;
        server_name meteor;
        # 证书配置
        ssl_certificate /etc/nginx/cert/server.crt;
        ssl_certificate_key /etc/nginx/cert/server.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;

        error_page 497 301 =307 https://$host:$server_port$request_uri;

        location / {
            root /mnt/data/meteor/html;
            index index.html index.htm;
			try_files $uri $uri/ /index.html;
        }
	   location /Galaxys/ {

			proxy_pass http://127.0.0.1:6012/Galaxys/;
			proxy_set_header X-Forwarded-Proto $scheme;
			proxy_set_header X-Forwarded-Host  $host;
			proxy_set_header X-Forwarded-Port 6012;
			proxy_set_header Host $host:6012;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";
			access_log off;
			client_max_body_size 1024m;
        }
		
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen 3461 ssl;
        server_name baudu;
        ssl_certificate /etc/nginx/cert/server.crt;
        ssl_certificate_key /etc/nginx/cert/server.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;

        location / {
            root   /mnt/data/comet/dist;
            index  index.html index.htm;
			try_files $uri $uri/ /index.html;
        }

        location /Galaxys/ {
			proxy_pass http://127.0.0.1:6905/Galaxys/;
               }
    }
    
    server {
        listen 4901 ssl;
        server_name dure;
        ssl_certificate /etc/nginx/cert/server.crt;
        ssl_certificate_key /etc/nginx/cert/server.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;

        location / {
            root   /mnt/data/stellar/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

		location /Galaxys/ {
           proxy_pass https://www.uyi.com/Galaxys/;
		}
    } 

    server {
        listen 8901 ssl;
        server_name supplier;
        ssl_certificate /etc/nginx/cert/server.crt;
        ssl_certificate_key /etc/nginx/cert/server.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;

        location / {
            root   /mnt/data/supplier/dist-dev;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

		location /Galaxys/ {
           proxy_pass https://iop.com/Galaxys/;
		}
    }
    
    server {
        listen 8718 ssl;
        server_name byu;
        ssl_certificate /etc/nginx/cert/server.crt;
        ssl_certificate_key /etc/nginx/cert/server.key;
        ssl_session_cache shared:sslcache:20m;
        ssl_session_timeout 10m;

        client_max_body_size 1280m;
		proxy_read_timeout 600;

        error_page 497 301 =307 https://$host:$server_port$request_uri;

		location / {
			proxy_pass http://127.0.0.1:8010;
			proxy_set_header X-Forwarded-Proto $scheme;
			proxy_set_header X-Forwarded-Host  $host;
			proxy_set_header X-Forwarded-Port 8011;
			proxy_set_header Host $host:8011;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";
			access_log off;

		}
		# You may need this to prevent return 404 recursion.
		location = /404.html {
				internal;
		}
    }
}
bash 复制代码
cd /etc/nginx
service nginx restart
或
systemctl restart nginx.service
相关推荐
苹果醋34 小时前
Java8->Java19的初步探索
java·运维·spring boot·mysql·nginx
雨雪飘零5 小时前
Windows系统使用OpenSSL生成自签名证书
nginx·证书·openssl
lihuhelihu5 小时前
第3章 CentOS系统管理
linux·运维·服务器·计算机网络·ubuntu·centos·云计算
yanwushu5 小时前
Xserver v1.4.2发布,支持自动重载 nginx 配置
mysql·nginx·php·个人开发·composer
Diamond技术流8 小时前
从0开始学习Linux——网络配置
linux·运维·网络·学习·安全·centos
Ven%15 小时前
centos查看硬盘资源使用情况命令大全
linux·运维·centos
JaneJiazhao15 小时前
HTTPSOK:SSL/TLS证书自动续期工具
服务器·网络协议·ssl
JaneJiazhao15 小时前
HTTPSOK:智能SSL证书管理的新选择
网络·网络协议·ssl
ajsbxi16 小时前
苍穹外卖学习记录
java·笔记·后端·学习·nginx·spring·servlet
上辈子杀猪这辈子学IT16 小时前
【Zookeeper集群搭建】安装zookeeper、zookeeper集群配置、zookeeper启动与关闭、zookeeper的shell命令操作
linux·hadoop·zookeeper·centos·debian