安装

安装地址:https://nginx.org/en/download.html

image-20221220123810378

Windows: 解压即可

Liunx:

1
apt-get install nginx

常见命令:

查看常见的命令:service nginx

启动: service nginx start

停止: service nginx stop

重启:service nginx restart

静态资源服务示例:

配置文件位置(一般位置,不同版本稍有不同):

windows: 安装路径下/conf/nginx.conf

Liunx: /etc/nginx/conf/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    server {

listen 80;

server_name space.mearc.top;

charset utf-8;

location / {

root C:/abc;

index index.html index.htm;

autoindex on;
}
}

Http转Https示例:

1
2
3
4
5
server {
listen 80;
server_name space.mearc.top;
rewrite ^(.*)$ https://$host$1 permanent;
}

SSL示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
server{
listen 443 ssl;
listen space.mearc.top;
server_name space.mearc.top;
ssl on;
ssl_certificate space.mearc.top_bundle.crt;
ssl_certificate_key space.mearc.top.key;

location / {
index index.html index.htm;
root /usr/share/nginx/wxres;
autoindex on;
}
}