Nginx configuration 80 port and 443 port

Docker configuration Nginx

uwsgi configuration, the following experiments share the same uwsgi, only fine-tuning

Preparation: server ssl Certificate, the front-end and back-end must have a certificate, which is required by the https protocol

The certificate can be placed in a separate directory, or it can be placed in the configuration file directory /etc/nginx/ ssl

# This is the settings.js request file content for the http protocol front end: http://www.testname.top:8080 backend prod.py file The CORS_ORIGIN_WHITELIST in the middle is: http://www.testname.top# This is the settings.js request file content for the https protocol front end: https://www.testname.top:8080 The prod.py file in the back end CORS_ORIGIN_WHITELIST is: https://www.testname.top
[uwsgi]#Used when connecting with nginx, the address of the server where the Django program is located socket=0.0.0.0:8000#Used as a web server directly, The address of the server where the Django program is located#http=0.0.0.0:8000#Project directory chdir=/home/moluo/luffycity#The directory of the wsgi.py file in the project, relative to the project directory wsgi-file=luffycity/wsgi.py# Number of processes processes=4# Thread count threads=2# The role of the uwsgi server master=True# The file storing the process number pidfile=uwsgi.pid# The log file, because uwsgi can run in the background without the terminal, the log is invisible. Our previous runserver is dependent on the terminal daemonize=uwsgi.log# Specify the dependent virtual environment virtualenv=/home/moluo/.virtualenv/luffycity

luffy project (double Container http)

Configure front-end project

Nginx configures port 80, which is the http protocol, configures front-end and back-end projects

Front-end static Page request
# Create a nginx container and provide services on port 80
# /usr/share/nginx/html is the project root directory assigned by the system by default when nginx is installed.
docker run -itd -p 80:80 -v /opt/luffy/luffycity/dist:/usr/share/nginx/html nginx
# Execute the above command, theoretically, you can make the front-end project, you can use Ali The IP address of the cloud has been accessed.
# Next we enter the operating system of nginx, through this system to understand how the front-end project runs.

# If you want to enter the nginx container to view the corresponding content, you can use the following command;
docker container exec -it [container ID] bash

"""< br />/etc/nginx # Configuration directory of nginx in nginx container
/usr/share/nginx/html # www directory in nginx container
"""

Create nginx container , Map nginx port -p and path -v

docker run -d -p 80:80 --name=cli_nginx -v /opt/ luffy/luffycity/dist:/usr/share/nginx/html nginx

View docke

docker ps -a
# Enter docker
docker exec -it cli_nginx(container id) bash
# Download vim
apt-get update
apt-get install -y vim

Configure Nginx configuration file

vim /etc/nginx/conf.d/default.conf

# Modify the domain name corresponding to server_name or ipserver{ listen 80; server_name www.testname.top ;'''' location / {root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; #This sentence, solve the 404 problem of other non-root pages }}

Restart nginx

# Check whether the configuration is successful nginx -t# Gracefully restart nginx -s reload

Configure back-end project

Create nginx container, map ngi nx port -p and path -v

docker run -d -p 8080:80 --name=ser_nginx -v /opt/luffy/ luffyserver/static/:/usr/share/nginx/static nginx

View docke

docker ps -a
# Enter docker
docker exec -it ser_nginx (Container id) bash
# Download vim
apt-get update
apt-get install -y vim

Configure Nginx configuration file

< code>vim /etc/nginx/conf.d/default.conf

# If there are multiple servers, you can continue to add server addresses here# Load balancing pool upstream luffy {server 127.0.0.1:8000; # server 127.0.0.1:8000 # can have multiple servers, weighted, etc.}#gzip on;server {listen 80; server_name api.testname.top;'''' location / {include uwsgi_params; uwsgi_pass luffy; # proxy_pass http:// luffy # This is a reverse proxy) # Back-end data request, when there is a static file request, transfer to here location /static {root /usr/share/nginx/; # The path does not need to go to the following file with the same name index index.html index.htm; try_files $uri $uri /index.html; }}

Restart nginx

 # Check whether the configuration is successful nginx -t# Smooth restart nginx -s reload

luffy project (single container http)

configuration front-end and back-end project

Create nginx container, map nginx port -p and path -v

docker run -d -p 80:80 -p 8080:80 --name=luffy_nginx -v /opt /luffy/luffycity/dist:/usr/share/nginx/html -v /opt/luffy/luffyserver/static/:/usr/share/nginx/static nginx

View docke

< pre>docker ps -a
# Enter docker
docker exec -it luffy_nginx(container id) bash
# Download vim
apt-get update
apt-get install -y vim

Configure Nginx configuration file

vim /etc/nginx/conf.d/default.conf

See Just put the content of the file in the same configuration file, this is a multi-virtual host, server is one, server_name distinguished

 upstream luffy {server 127.0.0.1:8000; # server 127.0.0.1:8000 # You can have multiple servers, weighted etc.}server{ listen 80; server_name www.testname.top;'''' location / {root /usr/share /nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; #This sentence solves the 404 problem of other non-root pages})server {listen 80; server_name api.testname.top ;'''' location / {include uwsgi_params; uwsgi_pass luffy; # proxy_pass http:// luffy # This is a reverse proxy) # Back-end data request, when there is a static file request, transfer to here location /static { root /usr/share/nginx/; # The path does not need to go to the file with the same name below index index.html index.htm; try_files $uri $uri /index.html; })

Restart nginx

# Check whether the configuration is successful nginx -t# Smooth restart nginx -s reload

luffy project (dual container https)

Configure front-end project

Create nginx container, map nginx port -p and path -v

docker run -d -p 80:80 -p 443:443 --name=cli_nginx -v /opt/luffy/luffycity/dist:/usr/share/nginx/html nginx

View docke

docker ps -a
# Enter docker
docker exec -it cli_nginx(container id) bash
# Download vim
apt- get update
apt-get install -y vim

Configure Nginx configuration file

vim /etc/nginx/conf.d/default.conf

# Front-end https configuration server {listen 443 ssl;server_name www.testname.top; #ssl on; ssl_certif icate /etc/nginx/ssl/cli/1_www.testname.top_bundle.crt; # This is the certificate we want to fill in ssl_certificate_key /etc/nginx/ssl/cli/2_www.testname.top.key; # This is the certificate we want to fill in The certificate ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_hers onserver_cipher_cipher ; location / {root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; })server {# If an http request comes in, redirect to https listen 80; server_name www.testname.top; rewrite ^(.*)$ https://$host$1 permanent; # If an http request comes in, it will be redirected to https #charset koi8-r; #access_log /var/log/ nginx/host.access.log main; error_page 500 502 503 504 /50x.html; location = /50x.html {root /usr/share/nginx/html;} }

Restart nginx

# Check whether the configuration is successful nginx -t# Smooth restart nginx -s reload

Configure backend project

< p>Create nginx container, map nginx port -p and path -v

# You can add more images Shoot port -p 8080:80, to prevent back-end managers from using http when requesting, you can redirect back to https to prevent errors, see the above docker run -d -p 8080:443 --name=ser_nginx -v /opt/luffy /luffyserver/static/:/usr/share/nginx/static -v /opt/luffy/ssl/:/etc/nginx/ssl nginx

View docke

docker ps -a
# Enter docker
docker exec -it ser_nginx(container id) bash
# Download vim
apt-get update
apt-get install -y vim

Configure Nginx configuration file

vim /etc/nginx/conf.d/default.conf

# Back-end load balancing pool upstream luffy {server 127.0.0.1:8000;}server {listen 443 ssl; server_name api.testname.top; ssl_certificate /etc/nginx/ssl/api/1_api.testname.top_bundle.crt ;# This is the certificate we want to fill in ssl_certificate_key /etc/nginx/ssl/api/2_api.testname.top.key; # This is the certificate we want to fill in ssl_session_timeout 5m; 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 / {in clude uwsgi_params; uwsgi_pass luffy; # proxy_pass http:// luffy # This is a reverse proxy} #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location /static {# backend Dynamic file root /usr/share/nginx/; index index.html index.htm; try_files $uri $uri/ /index.html;} error_page 500 502 503 504 /50x.html; location = /50x.html {root / usr/share/nginx/html;} }

Restart nginx

# Check whether the configuration is successful nginx -t# Smooth restart nginx -s reload

luffy project (single container https)

Create nginx container, map nginx port -p and path -v< /code>

# You can add more mapping ports -p *:80 (*represents all ports and can be accessed), to prevent the background manager from using http when requesting, you can redirect back https, to prevent errors, redirect to see above docker run -d -p 443:443 -p 8080:443 -p 80:80 --name=luffycity -v /opt/luffy/luffyclient/dist/:/usr/share/ nginx/html -v /opt/luffy/luffyserver/luffyserver/static/:/usr/share/nginx/static -v /opt/luffy/ssl/:/etc/nginx/ssl nginx

View docke

docker p s -a# Enter docker docker exec -it luffycity(container id) bash# Download vimapt-get updateapt-get install -y vim

Configure the Nginx configuration file

Seeing just put the file The content is placed in the same configuration file, this is a multi-virtual host, server is one, server_name distinguished

vim /etc/nginx /conf.d/default.conf

# Load balancing pool upstream luffy {server 127.0.0.1:8000;}server {listen 443 ssl;server_name www.testname. top;#ssl on; ssl_certificate /etc/nginx/ssl/cli/1_www.testname.top_bundle.crt; # This is the certificate we want to fill in ssl_certificate_key /etc/nginx/ssl/cli/2_www.testname.top.key; # This is the certificate we want to fill in ssl_session_timeout 5m; 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 / {root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; })server {listen 80; server_name www.testname .top; rewrite ^(.*)$ https://$host$1 permanent; #charset koi8-r; #access_log /var/log/nginx/ host.access.log main; error_page 500 502 503 504 /50x.html; location = /50x.html {root /usr/share/nginx/html;}} server {listen 443 ssl; server_name api.testname.top; ssl_certificate /etc/nginx/ssl/api/1_api.testname.top_bundle.crt; # This is the certificate we want to fill in ssl_certificate_key /etc/nginx/ssl/api/2_api.testname.top.key; # This is what we want to fill in Certificate ssl_session_timeout 5m; 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_cipher location / {include uwsgi_params; uwsgi_pass luffy;} #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location /static {root /usr/share/nginx/; index index.html index .htm; try_files $uri $uri/ /index.html;} error_page 500 502 503 504 /50x.html; location = /50x.html {root /usr/share/nginx/html;}} 

Restart nginx

# Check whether the configuration is successful nginx -t# Gracefully restart nginx -s reload

Leave a Comment

Your email address will not be published.