I'm trying to set up Ngnix for my two Websites, both websites are hosted on the Same AWS EC2 Instances. My first website was built with NextJS and my second one was WordPress. For the current version of the webpage is with NextJS so now I need to do this type of routing:
www.domain.com/ => Need to do routing on WordPress site www.domain.com/blog => Need to do routing on WordPress site www.domain.com/<any-page> => Need to do routing on NextJS site
NextJs hosted on localhost:3000 Wordpress Directory located at /var/www/wordpress
Still I didn't tried to host WordPress on route but i tried that for blogs but it's not working fine for me. Here is my configuration:
server {
root /var/www/other;
index index.html index.htm index.nginx-debian.html;
server_name domain.com www.domain.com;
if ($host = domain.com) {
return 301 https://www.$host$request_uri;
} # managed by Certbot
location / {
proxy_pass http://localhost:3000;
}
location /blog {
alias /var/www/html/wordpress;
index index.php index.html index.htm;
try_files $uri $uri/ /wordpress/index.php?$args;
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.com-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.com-0001/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 = www.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = domain.com) {
return 301 https://www.$host$request_uri;
} # managed by Certbot
server_name domain.com www.domain.com;
listen [::]:80;
listen 80;
return 404; # managed by Certbot
}