centos安装nginx,部署前端项目,并配置SSL与CDN

centos安装nginx,部署前端项目,并配置SSL与CDN

安装nginx

1、下载安装包
http://nginx.org/download/nginx-1.18.0.tar.gz

2、将安装包上传到服务器使用命令解压
tar zxvf nginx-1.18.0.tar.gz

3、进入Nginx目录下
cd /nginx/nginx-1.18.0

4、配置安装运行目录
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

注意:
若是报错直接执行这个命令
yum -y install gcc openssl-devel pcre-devel zlib-devel

5、再次执行第4步
./configure --prefix=/usr/local/nginx

6、执行编译安装
make && make install

7、安装完毕,进入Nginx下的sbin目录并启动nginx
cd /usr/local/nginx/sbin
./nginx

8、如果需要修改配置文件 ,修改之后要重新加载配置文件
nginx -s reload

9、启动nginx方式
./nginx

./nginx -c /usr/local/nginx/conf/nginx.conf

配置SSL

1、打开443端口的配置
需要配置防火墙放行443端口
放行防火墙端口
将证书文件上传到cert目录下面
并设置80端口强跳转443


#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;
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    # 配置禁用 gzip 条件,支持正则,此处表示 ie6 及以下不启用 gzip(因为ie低版本不支持)
    gzip_disable "MSIE [1-6]\."; 

    server {
        listen       8088;
        server_name  www.cilicili.top;
       # rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            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;
        #}
    }
    server {
        listen       80;
        server_name  www.cilicili.top;
        rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            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       8088;
    server_name  127.0.0.1;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    
    location / {
        root   /usr/share/nginx/html;
        try_files $uri $uri/ /index.html last;
        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   /usr/share/nginx/html;
    }
 

}
    server {
        listen       443 ssl;
        server_name  www.cilicili.top;

        ssl_certificate      /usr/local/nginx/cert/cilicilipem.pem;
        ssl_certificate_key  /usr/local/nginx/cert/cilicilikey.key;

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

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

         location / {
            proxy_pass http://dns.cilicili.top;
            proxy_redirect off;
            proxy_set_header HOST $proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }


        location ~ /server/{
          proxy_pass http://server.cilicili.top:8083;
      
        }

        location /aa {
            root   html;
            index  index.html index.htm;
        }

        location /qqcalback/ {
            proxy_pass http://server.cilicili.top:8083/QQCallBack;
            proxy_redirect off;
            proxy_set_header HOST $proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }

    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在CentOS 7上配置NginxSSL模块,您可以按照以下步骤进行操作: 1. 安装Nginx:首先,确保您的系统已安装Nginx。如果没有安装,可以使用以下命令安装: ``` sudo yum install nginx ``` 2. 生成SSL证书和私钥:使用以下命令生成SSL证书和私钥文件: ``` sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/nginx.key -out /etc/nginx/nginx.crt ``` 在执行此命令后,您将被要求提供一些信息,如国家、组织、通用名称等。请根据您的需求填写这些信息。 3. 配置Nginx:打开Nginx配置文件`/etc/nginx/nginx.conf`并进行以下更改: a. 找到`server`段并添加以下行以启用SSL: ``` listen 443 ssl; ssl_certificate /etc/nginx/nginx.crt; ssl_certificate_key /etc/nginx/nginx.key; ``` b. 如果您希望将HTTP流量重定向到HTTPS,请添加以下行以在`server`段中启用重定向: ``` server { listen 80; server_name example.com; return 301 https://$host$request_uri; } ``` c. 保存并关闭文件。 4. 检查配置文件:运行以下命令检查Nginx配置文件是否正确: ``` sudo nginx -t ``` 如果没有错误,将显示`nginx: configuration file /etc/nginx/nginx.conf test is successful`。 5. 重启Nginx:运行以下命令重启Nginx以使更改生效: ``` sudo systemctl restart nginx ``` 现在,您的Nginx服务器已配置为使用SSL模块。您可以使用HTTPS访问您的网站,并且所有传输的数据都将通过SSL进行加密。请确保将上述示例中的`example.com`替换为您自己的域名。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码头薯条Pro

本文能帮到阁下,在下很开心!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值