AFNetworking + Nginx + HTTPS Server Communication

Source: Internet
Author: User

AFNetworking + Nginx + HTTPS Server Communication

This article describes how to use AFNetworking for secure communication with HTTPS backend interfaces on iOS. 2. describes how to create a self-signed certificate in the background. 3. And the Web site on the Linux platform where Nginx configures the HTTPS protocol interface.

This question about the secure HTTPS communication of AFNetworking is a bit uncertain for many people who have never experienced it for the first time or even once. It is actually very simple:

  • A. If the dynamic certificate configured for the backend server is issued by a ca certificate, the user can use AFNetworking to access the backend interface in the same way as http.
  • B. however, if an HTTPS certificate is issued by a well-known CA, the problem may occur. AFNetworking rejects communication with such backend servers by default, because the verification fails, just like opening the 12306 website to grab a ticket, the certificate was not issued by the CA, but signed by the Ministry of Railways. Therefore, for small and medium-sized startups or growth companies, buying an https certificate also costs a lot. Therefore, when performing background communication, you generally use a self-signed certificate to implement the https interface. You can use the following openssl command to generate a self-signed certificate:
openssl req -new -x509 -nodes -days 365 -newkey rsa:1024  -out tv.diveinedu.com.crt -keyout tv.diveinedu.com.key

Where:-days 365 indicates the validity period of the certificate, in days, from the time when the command is run;-newkey rsa: 1024 indicates that the new certificate uses the 1024-bit RSA asymmetric encryption algorithm; -out: Specify the output Certificate file name-keyout: Specify the output private key file name. After this command is run, you need to enter some settings:

Country Name (2 letter code) [AU]:CNState or Province Name (full name) [Some-State]:HunanLocality Name (eg, city) :ChangshaOrganization Name (eg, company) [Internet Widgits Pty Ltd]:tv.diveinedu.comOrganizational Unit Name (eg, section) :MarketCommon Name (e.g. server FQDN or YOUR name) :tv.diveinedu.comEmail Address :diveinedu@qq.com

If you are interested in building the Linux background HTTPS service, you need to upload the certificate and private key to the server or directly generate the certificate on the server and configure the certificate to the background server, take Nginx as an example to make the following settings:

  • 1. Add an Nginx virtual host configuration file first,
sudo touch /etc/nginx/sites-available/tv.diveinedu.com
  • 2. Make the configuration file take effect:
sudo ln -sf /etc/nginx/sites-available/tv.diveinedu.com /etc/nginx/sites-enabled/tv.diveinedu.com
  • 3. edit the file:
sudo vim /etc/nginx/sites-enabled/tv.diveinedu.com
  • 4. Press I to enter the VIM editing mode and enter the configuration as follows:
Server {listen 80; # HTTP default port 80 server_name TV .diveinedu.com; # HOST name, which matches access_log/var/log/nginx/TV .diveinedu.com with the HOST in the HTTP Request Header domain. log; # access log path return 301 https: // $ server_name $ request_uri; # force redirect all http access requests to https} server {listen 443; # HTTPS default port 443 ssl on; # Open SSL Secure Socket ssl_certificate/etc/nginx/TV .diveinedu.com. crt; # Certificate file path ssl_certificate_key/etc/nginx/TV .diveinedu.com. key; # private key file path server_name TV .diveinedu.com; # HOST name, which matches access_log/var/log/nginx/TV .diveinedu.com with the HOST in the HTTP Request Header domain. log; # access log path location/{root/var/www/TV .diveinedu.com/## 文 root directory index. php index.html; # default homepage }}
  • 5. Press ESC and exit the VIM edit mode. Then press x and press enter to save and exit in Vim. Then run the Nginx Configuration File Syntax check command to check whether the configuration is correct:
nginx -t

If there are no errors, the output will be:

nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
  • 6. Then, you only need to restart the Nginx server.
sudo service nginx restart

Then go to your domain name service provider background and resolve your domain name to the server to the IP address to allow free access, but the browser access will be automatically organized and displayed with a warning, manually add to trust.

If the company has money to provide users with better services and experience, it is best to register with a well-known CA to apply for a valid certificate! Otherwise, the browser (Chome) will look like this:

 

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.