This article mainly introduces the method of configuring the same domain name for the front-end and back-end of nginx, and shares it with you. The details are as follows: upstream dfct { #ip_hash; server 121.41.19.236:8192; } server { server_name ct.aeert.com; location / { root /opt/web; try_files $uri $uri/ /index.html; error_page 405 =200 http://$host$request_uri; } location ^~/web/ { proxy_set_header Host $proxy_host; # 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_pass http://121.41.19.236:8192/; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/ct.aeert.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/ct.aeert.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot } server { if ($host = ct.aeert.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; server_name ct.aeert.com; return 404; # managed by Certbot } Supplement: Three ways to deploy projects with separated front-end and back-end using nginx For projects with separated front-end and back-end, the front-end and back-end can use different domain names or the same domain name. The following is the case where the frontend and backend use the same domain name: 1. The front end uses www.xxx.com and the back end uses api.xxx.com server { server_name www.xxx.com; location / { root /tmp/dist; index index.html; try_files $uri $uri/ /index.html; } } server { server_name api.xxx.com; location / { uwsgi_pass 127.0.0.1:8000; include /etc/nginx/uwsgi_params; } } 2. The front end uses www.xxx.com and the back end uses www.xxx.com/api/ 1. If uwsgi uses http, it can be configured like this server { server_name www.xxx.com; location / { root /tmp/dist; index index.html; try_files $uri $uri/ /index.html; } location ^~ /api/ { proxy_pass http://127.0.0.1:8000/; } } 2. If uwsgi uses the socket method, it needs to be configured like this server { server_name www.xxx.com; location / { root /tmp/dist; index index.html; try_files $uri $uri/ /index.html; } location ^~ /api/ { proxy_pass http://127.0.0.1:8080/; } } server { listen 8080; location / { uwsgi_pass 127.0.0.1:8000; include /etc/nginx/uwsgi_params; } } This is the end of this article about how to configure the same domain name for the front-end and back-end of nginx. For more information about configuring the same domain name for the front-end and back-end of nginx, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Example code of how to create a collapsed header effect using only CSS
>>: TinyEditor is a simple and easy-to-use HTML WYSIWYG editor
Preface When it comes to database transactions, a...
Table of contents App Update Process Rough flow c...
Preface In the previous interview process, when a...
1. Linux installation (root user operation) 1. In...
Songti: SimSun Bold: SimHei Microsoft YaHei: Micr...
Preface Hello everyone, this is the CSS wizard - ...
After the form is submitted, the returned HTML pag...
Table of contents 1. Check whether the docker env...
Let's take a look at ufw (Uncomplicated Firew...
Preface This article contains 1. Several major co...
Configure Git environment in Docker At work, I en...
This article shares the specific code of JavaScri...
If your MySQL database is installed on a centos7 ...
background The popularity of Docker is closely re...
Table of contents 1. Background 2. Local custom i...