本篇记录使用Nginx的一些tricks。
一、更改默认Web根目录
修改配置文件
Nginx默认的Web根目录是:/usr/share/nginx/html/,一般我们都是习惯的是:/var/www/html。现进行更改,具体操作如下:
[lz@mail ~]$ sudo cat /etc/nginx/conf.d/default.conf
server {
listen ;
server_name 192.168.202.129; root /var/www/html; index index.php index.html index.htm; location / {
try_files $uri $uri/ =;
}
error_page /.html;
error_page /50x.html;
location = /50x.html {
root /var/www/html;
} location ~ \.php$ {
try_files $uri =;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
修改root处的配置为: root /var/www/html;
重启服务
[lz@mail ~]$ sudo service nginx restart
Redirecting to /bin/systemctl restart nginx.service
[lz@mail ~]$ sudo service nginx status
Redirecting to /bin/systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 五 -- :: CST; 6s ago
Docs: http://nginx.org/en/docs/
Process: ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=/SUCCESS)
Process: ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=/SUCCESS)
Main PID: (nginx)
CGroup: /system.slice/nginx.service
├─ nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─ nginx: worker process 8月 :: mail.starnight.com systemd[]: Starting nginx - high performance web server...
8月 :: mail.starnight.com systemd[]: Started nginx - high performance web server.
References: