一、去域名服务商解析域名到服务器ip
二、进入服务器nginx配置目录
如一个服务器要运行多个项目,可在nginx.conf文件同一级目录下扩展多域名配置:
例:创建vhost目录,vhost目录下根据域名数创建域名配置。
例:域名(mask.test.com)可创建mask.conf,配置内容可网上搜索,很多案例,这里说明几个重要点:
代码段中有##前缀的是需要替换自己的配置的
1、https协议,证书的配置;
端口:443
证书路径配置(例)
server
{
listen 443 ssl;
#listen [::]:80;
server_name ##your_hostname;
#ssl on;
index index.html index.htm index.php default.html default.htm default.php;
root ##your_project_path;
ssl_certificate ##your_cert_path;
ssl_certificate_key ##your_key_path;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#include other.conf;
#error_page 404 /404.html;
location / {
if (!-e $request_filename) {
rewrite ^/api/(.*)$ /api.php/$1 last;
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ .*\.(txt)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/xx.log;
}
2、http强制跳转https;
server
{
listen 80;
#listen [::]:80;
server_name ##your_hostname;
index index.html index.htm index.php default.html default.htm default.php;
root ##your_project_path;
return 301 https://$server_name$request_uri;
}
3、域名配置完后需要在nginx.conf文件最后(http配置大括号里面)include子配置。
include vhost/*.conf