Duke Yin's Technology database

群晖WebStation 添加自定义nginx配置

Webstation虽然也可以用Apache,但是群晖自带了个nginx,多装一个Apache浪费资源,所以直接用自带的,

当我们创建一个虚拟主机之后,在如下路径会自带新建一个随机名称的文件夹,如:

/usr/local/etc/nginx/conf.d/
/usr/local/etc/nginx/conf.d/34f86b46-70b6-4c2c-a707-028029b04d03/

此随机名称文件夹对应群晖WebStation的虚拟主机。

在此文件夹下新建文件:

touch user.conf

此文件会被自动include,然后我们可以在此文件中写入Nginx配置,然后用命令重载nginx即可生效:

sudo nginx -s reload

需要注意的是,这个文件只是配置文件的一部分,所以不能有server{},只能写点location,对于防盗链什么的也足够用了。

使用nginx建WordPress的话,可以将nginx伪静态配置也放在里面。

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

或者

rewrite ^.*/files/(.*)$ /wp-includes/ms-files.php?file=$1 last;
if (!-e $request_filename){
rewrite ^.+?(/wp-.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /index.php last;
}

#

发布评论

评论

标注 * 的为必填项。