本篇记录使用Nginx的一些tricks。
一、更改默认Web根目录
修改配置文件
Nginx默认的Web根目录是:/usr/share/nginx/html/,一般我们都是习惯的是:/var/www/html。现进行更改,具体操作如下:
[lz@mail ~]$ sudo cat /etc/nginx/conf.d/default.conf server { listen 80; server_name 192.168.202.129; root /var/www/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } location ~ .php$ { try_files $uri =404; 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 五 2018-08-17 16:49:06 CST; 6s ago Docs: http://nginx.org/en/docs/ Process: 3768 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS) Process: 3773 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 3774 (nginx) CGroup: /system.slice/nginx.service ├─3774 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─3775 nginx: worker process 8月 17 16:49:06 mail.starnight.com systemd[1]: Starting nginx - high performance web server... 8月 17 16:49:06 mail.starnight.com systemd[1]: Started nginx - high performance web server.
References: