Welcome! Log In Create A New Profile

Advanced

Changing Root Directory

Posted by ShinShin 
Changing Root Directory
January 04, 2021 10:07PM
Hello everyone,

I built a WordPress site working fine. The address is "http://mydomain.com" for example.

Then I would like to indicate "http://mydomain.com/data/" to /home/data/index.html .
So I modified the following /etc/nginx/default.d/locations.conf file.

$ cat locations.conf
location ~* /wp-config.php {
deny all;
}

# Beginning of Insertion this time
location /data/ {
root /home/data;
index index.html;
}
# End of Insertion this time

location / {
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
$

After restarting nginx I accessed "http://mydomain.com/data/".
Then browser showed /usr/share/nginx/html/404.html file.

The permission and owner of /home/data/index.html is the following.

$ LANG=en ls -la /home/data
total 4
drwxrwxrwx 2 nginx nginx 24 Jan 5 11:52 .
drwxr-xr-x. 5 root root 42 Jan 5 11:37 ..
-rw-rw-r-- 1 nginx nginx 142 Dec 15 18:30 index.html
$

How should I write the configuration file?
Please help me.
Re: Changing Root Directory
January 20, 2021 06:04PM
I didn't show information enough.

/etc/nginx/nginx.conf is below.

$ cat /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server {
listen 80;
listen [::]:80;
# server_name _;
server_name www.mydomain.com;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}

Somebody, please help me.
Re: Changing Root Directory
January 21, 2021 03:34AM
location /data/ {
root /home/data;

Becomes /home/data/data

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 71
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready