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
Table of contents 1. Basic storage of files and d...
Table of contents 1: Single machine password-free...
Overview Let's summarize some SQL statements ...
Introduction yum (Yellow dog Updater, Modified) i...
1. Scenario display The tomcat log occasionally r...
<br />User experience is increasingly valued...
<br />The content is reproduced from the Int...
Table of contents Why do we need Docker? Docker d...
The paging effect is implemented in the vue proje...
As shown in the figure: But when viewed under IE6...
I have previously shared the usage of asynchronou...
Initialize Data DROP TABLE IF EXISTS `test_01`; C...
Today I made a menu button. When you move the mous...
Preface The three-column layout, as the name sugg...
Record the BUG that got me stuck all afternoon to...