最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】CentOS更新nginx配置使得小程序能访问测评系统的Flask后台接口

nginx crifan 1247浏览 0评论
折腾:
【未解决】部署测评系统Flask后台到在线服务器
期间,服务器中flask后台已正常运行,Postman和浏览器都可以访问接口了。
现在接着要去更新nginx配置,使得加上https,这样小程序才能调用接口。
[root@xxx-general-01 logs]# cd /etc/nginx/
conf.d/                 fastcgi.conf.default    koi-utf                 mime.types.default      proxy_params            uwsgi_params            
default.d/              fastcgi_params          koi-win                 nginx.conf              scgi_params             uwsgi_params.default    
fastcgi.conf            fastcgi_params.default  mime.types              nginx.conf.default      scgi_params.default     win-utf                 
[root@xxx-general-01 logs]# cd /etc/nginx/conf.d/
[root@xxx-general-01 conf.d]# pwd
/etc/nginx/conf.d
[root@xxx-general-01 conf.d]# ll
total 4
-rw-r--r-- 1 root root 3084 Nov 28 11:21 dev.xxx.conf
[root@xxx-general-01 conf.d]# sz dev.xxx.conf 
rz
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring dev.xxx.conf...
  100%       3 KB       3 KB/sec    00:00:01       0 Errors  
去编辑:
dev.xxx.conf
加上:
    location /evaluation/ {
        proxy_pass http://127.0.0.1:34800/;
    }
nginx更新配置:
[root@xxx-general-01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@xxx-general-01 conf.d]# nginx reload
nginx: invalid option: "reload"
[root@xxx-general-01 conf.d]# service nginx reload
Redirecting to /bin/systemctl reload nginx.service
[root@xxx-general-01 conf.d]# nginx -s reload             
[root@xxx-general-01 conf.d]# nginx status
nginx: invalid option: "status"
[root@xxx-general-01 conf.d]# service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2018-11-19 17:10:17 CST; 1 months 1 days ago
  Process: 14358 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 15740 (nginx)
   CGroup: /system.slice/nginx.service
           ├─14512 nginx: worker process
           ├─14513 nginx: worker process
           ├─14514 nginx: worker process
           ├─14515 nginx: worker process
           └─15740 nginx: master process /usr/sbin/nginx

Nov 19 17:10:17 xxx-general-01 nginx[15734]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Nov 19 17:10:17 xxx-general-01 nginx[15734]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Nov 19 17:10:17 xxx-general-01 systemd[1]: Started The nginx HTTP and reverse proxy server.
Nov 28 10:54:44 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Nov 28 11:01:10 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Nov 28 11:08:25 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Nov 28 11:13:28 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Nov 28 11:17:56 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Nov 28 11:22:42 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
Dec 21 18:28:33 xxx-general-01 systemd[1]: Reloaded The nginx HTTP and reverse proxy server.
去访问接口试试
可以了:
【总结】
此处只需要去,之前配置好的nginx的配置:
/etc/nginx/conf.d/
中的:
dev.xxx.conf
添加对应的配置:
    location /evaluation/ {
        proxy_pass http://127.0.0.1:34800/;
    }
变成:
server {
    listen              443 ssl;
    listen              [::]:443 ssl;
    server_name         dev.xxx;

    access_log          /var/log/nginx/dev.xxx/access_https.log;
    error_log           /var/log/nginx/dev.xxx/error_https.log;

    ### Https Related Config
    ssl_certificate     /usr/share/nginx/cert/dev.xxx_aliyun_symantec_free_ov_ssl.crt; # 证书文件
    ssl_certificate_key /usr/share/nginx/cert/dev.xxx_aliyun_symantec_free_ov_ssl.key; # 私钥文件

    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    keepalive_timeout   70; # 设置长连接

    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;

    location /storybook/ {
        # proxy_pass https://xxx:33800/;
        # proxy_pass https://127.0.0.1:33800/;
        proxy_pass http://127.0.0.1:33800/;
    }

    location /evaluation/ {
        proxy_pass http://127.0.0.1:34800/;
    }
}
再去重新加载nginx配置:
service nginx reload
即可。

转载请注明:在路上 » 【已解决】CentOS更新nginx配置使得小程序能访问测评系统的Flask后台接口

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.192 seconds, using 22.14MB memory