Created
December 16, 2018 12:22
-
-
Save JaosnHsieh/baa1167a4832b763d1c6de066202bfc5 to your computer and use it in GitHub Desktop.
next.js as frontend app, strapi as api server, nginx server config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #################### | |
| # Upstream Servers # | |
| #################### | |
| upstream example { | |
| server localhost:3000; | |
| } | |
| upstream api { | |
| server localhost:1337; | |
| } | |
| ######################### | |
| # HTTPS example.com # | |
| ######################### | |
| server { | |
| # Listen HTTP | |
| listen 80; | |
| server_name example.com; | |
| # Proxy Config | |
| location / { | |
| proxy_pass http://example; | |
| proxy_http_version 1.1; | |
| proxy_set_header X-Forwarded-Host $host; | |
| proxy_set_header X-Forwarded-Server $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 Host $http_host; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "Upgrade"; | |
| } | |
| } | |
| ############################# | |
| # HTTPS api.example.com # | |
| ############################# | |
| server { | |
| # Listen HTTPS | |
| listen 80; | |
| server_name api.example.com; | |
| # Proxy Config | |
| location / { | |
| proxy_pass http://api; | |
| proxy_http_version 1.1; | |
| proxy_set_header X-Forwarded-Host $host; | |
| proxy_set_header X-Forwarded-Server $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 Host $http_host; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "Upgrade"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #################### | |
| # Upstream Servers # | |
| #################### | |
| upstream example { | |
| server localhost:8080; | |
| } | |
| upstream api { | |
| server localhost:1337; | |
| } | |
| ######################## | |
| # HTTP API example.com # | |
| ######################## | |
| server { | |
| # Listen HTTP | |
| listen 80; | |
| server_name example.com; | |
| # Else Redirect to HTTPS // API | |
| location / { | |
| return 301 https://$host$request_uri; | |
| } | |
| } | |
| ######################### | |
| # HTTPS API example.com # | |
| ######################### | |
| server { | |
| # Listen HTTPS | |
| listen 443 ssl; | |
| server_name example.com; | |
| # Root Location | |
| root /var/www/html/example.com; | |
| # SSL Config | |
| ssl_certificate /path/to/your/crt; | |
| ssl_certificate_key /path/to/your/key; | |
| # Proxy Config | |
| location / { | |
| proxy_pass http://example; | |
| proxy_http_version 1.1; | |
| proxy_set_header X-Forwarded-Host $host; | |
| proxy_set_header X-Forwarded-Server $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 Host $http_host; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "Upgrade"; | |
| } | |
| } | |
| ############################ | |
| # HTTP API api.example.com # | |
| ############################ | |
| server { | |
| # Listen HTTP | |
| listen 80; | |
| server_name api.example.com; | |
| # Else Redirect to HTTPS // API | |
| location / { | |
| return 301 https://$host$request_uri; | |
| } | |
| } | |
| ############################# | |
| # HTTPS API api.example.com # | |
| ############################# | |
| server { | |
| # Listen HTTPS | |
| listen 443 ssl; | |
| server_name api.example.com; | |
| # Root Location | |
| root /var/www/html/api.example.com; | |
| # SSL Config | |
| ssl_certificate /path/to/your/crt; | |
| ssl_certificate_key /path/to/your/key; | |
| # Proxy Config | |
| location / { | |
| proxy_pass http://api; | |
| proxy_http_version 1.1; | |
| proxy_set_header X-Forwarded-Host $host; | |
| proxy_set_header X-Forwarded-Server $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 Host $http_host; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection "Upgrade"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 127.0.0.1 example.com api.example.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment