Answer the question
In order to leave comments, you need to log in
How to set up NGINX to have different sites in different folders?
There is a folder in which the site is located /var/www/dev.example.com
Inside the site folder there are two folders - forum and public
The following config is used
server {
listen 80;
#listen [::]:80;
listen 443 ssl http2;
#listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/dev.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/dev.example.com/privkey.pem;
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
server_name dev.example.com;
charset utf-8;
access_log /var/log/nginx/dev.example.com.access.log;
error_log /var/log/nginx/dev.example.com.error.log;
root /var/www/dev.example.com/public;
index index.html index.htm index.php;
# Dev-хост, отключение кеширования
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
# Не удалять! Нужно для обновления сертификатов от Let's Encrypt
location ~ /.well-known/acme-challenge {
allow all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Answer the question
In order to leave comments, you need to log in
For forum, add a separate location.
location /forum {
root /var/www/dev.example.com;
try_files $uri $uri/ /forum/index.php$is_args$args;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question