Nginx-ubuntu install Nginx and configure https

1. Demand###

**Introduction: ** When we deploy the application, we hope to use Nginx and configure https. I have read a lot of articles on the Internet, but they are not very systematic. So write this article for future use.

Second, install Nginx

  1. Get the installation package
wget http://nginx.org/download/nginx-1.17.10.tar.gz
  1. Unzip
tar -zxvf nginx-1.17.10.tar.gz
  1. Configuration
. /configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

But it will report an error directly

. /configure: error: invalid option "--with-http_ssl_moudle"

Need to install dependencies

apt-get install gcc
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g zlib1g-dev
# Ubuntu14.No openssl was found in 04's warehouse-dev, by the following openssl and libssl-dev alternative
# apt-get install openssl openssl-dev
sudo apt-get install openssl 
sudo apt-get install libssl-dev
sudo apt-get install libpcre3 libpcre3-dev

Then run the sentence above

installation

make 
make install

Three, configure https

  1. Store the https certificate in the /usr/local/nginx/conf directory, I created a new folder cert

  2. Edit the configuration file /usr/local/nginx/conf/nginx.conf as follows:

server {
  listen       80;
  server_name your domain name;return301 https://Your domain name$request_uri;

  # charset koi8-r;

  # access_log  logs/host.access.log  main;

  location /{
   proxy_pass http://127.0.0.1:8080;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Forwarded-Port $server_port;}}

server {
  listen       443 ssl;
  server_name your domain name;

  ssl_certificate      cert/Your certificate crt;
  ssl_certificate_key  cert/Your certificate key;

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

  # ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_session_timeout 24h;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers  on;

  location /{
   proxy_pass http://127.0.0.1:8080;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Forwarded-Port $server_port;}

  location /pic {
   proxy_pass http://127.0.0.1:8081;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Forwarded-Port $server_port;}}

Four, SpringBoot configuration use

  1. The configuration is as follows:
server:
 port:8080
 tomcat:
 remote-ip-header: x-forwarded-for
 protocol-header: x-forwarded-proto
 port-header: X-Forwarded-Port
 use-forward-headers:true

Recommended Posts

Nginx-ubuntu install Nginx and configure https
ubuntu install and configure GitLab
Centos6.5 install and configure mongodb
Install and configure keepalived under CentOS 5.9
Install and configure MySQL on Ubuntu
Install and configure Docker in Ubuntu
CentOS 8 - install and configure NFS service
CentOS Minimal install and configure TIPS
Install and configure FreeIPA in Centos7
Ubuntu install PHP and PHP Nginx configuration method
Centos7 install Nginx
How to install and configure NATS on Ubuntu 16.04
How to install and configure Gogs on Ubuntu 18.04
VMware Fusion install CentOS7 and configure the network
How to install and configure Elasticsearch on CentOS 7
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and configure VNC on CentOS 8
How to install and configure Ansible on Ubuntu 18.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure Redis on CentOS 8
How to install and configure PostGIS on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
How to install and configure AppScale on Ubuntu 12.04
How to install and configure Redmine on CentOS 8
How to install and configure PostGIS on Ubuntu 14.04
Install centos7 and connect
How to install and configure NFS server on CentOS 8
ubuntu install nginx server
Install and configure Mono production environment on Ubuntu Server
How to install and configure Postfix mail server on CentOS8
Install and configure the latest version of RabbitMQ-3.8.5 (with video)
How to compile and install PHP and Nginx in Ubuntu environment
Detailed steps to install and configure k8s cluster in centos 7
Ubuntu Apache configure https certificate
centos7 install python3 and ipython
Know Linux and install CentOS
CentOS 7 install Mono and MonoDevelop
Ubuntu 16.04 compile and install PHP 7.2
ubuntu18.04 compile and install python3.8
CentOS6.5 install Java 8 and Tomcat8
Centos compile and install Git
Tencent Cloud Centos install nginx
CentOS7 install python3 and pip3
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS6 install and crack confluence
CentOS 6 compile and install python 3
Ubuntu16.04 install SVN and configuration
Ubuntu16.04 install and uninstall VMware-Workstation 14
CentOS6 install and crack Jira 7