阅读 98

nginx绑定域名(https)

#查看启动情况

ps -ef|grep nginx

#查看是否启动成功

curl 192.168.0.177

#查看端口情况

netstat -ano|grep 80

修改nginx配置(我的nginx是安装在/lnmp/nginx上的):

vim /lnmp/nginx/conf/nginx.conf

 在/lnmp/nginx/vhost/ 中新建test.conf

vim test.conf

配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#测试
server {
    # 监听端口
    listen       8989;
    # 绑定域名
    server_name  120.53.29.187;
    # 编码
    charset utf-8;
    # 网站根目录,可自定义
    root   /www/web;
    # 主机默认文档
    index index.html index.php;
    # 成功与错误日志
    access_log  /www/weblogs/test.access.log main gzip=4 flush=5m;
    error_log   /www/weblogs/test.error.log;
    # URL重写(根据实际需求填写,以下是默认跳转index.php)
    location / {
        if (!-e $request_filename) {
            rewrite ^/index.php(.*)$ /index.php?s=$1 last;
            rewrite ^/(.*)$ /index.php?s=$1 last;
            break;
        }
    }
 
    # nginx 和 php 关联
    # 配置FastCGI,PHP 脚本请求全部转发到 FastCGI处理
    location ~ .*\.php$ {
        # 设置监听端口(多版本php用端口号区分)
        fastcgi_pass   127.0.0.1:9000;
        # 设置脚本文件请求的路径
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        # 引入fastcgi的配置文件
        include        fastcgi_params;
    }
 
}  

若需要配置https,则配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# test
server {
    listen 80;
    server_name www.test.com;
    location / {
        # 301 跳转到https带上url参数$request_uri;
        return 301 https://$server_name$request_uri;
    }
}
server {
    # 监听443端口
    listen       443;
    # 绑定域名
    server_name  www.test.com;
    # 编码
    charset utf-8;
    # 网站根目录
    root   /www/web;
    # 主机默认文档
    index  index.html index.php;
    # 成功与错误日志
    access_log  /www/weblogs/www.test.com.access.log;
    error_log   /www/weblogs/www.test.com.error.log;
    # 开启ssl
    ssl on;
    # ssl证书存放路径
    ssl_certificate /www/ssl/2019/2906479_www.test.com.pem;
    # ssl证书存放路径
    ssl_certificate_key /www/ssl/2019/2906479_www.test.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    # 按照这个协议配置
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    # 按照这个配置
    ssl_prefer_server_ciphers on;
    # URL重写(根据实际需求填写)
    location / {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?s=/$1 last;
        }
        try_files $uri $uri/ /index.php?$args;
    }
    # nginx 和 php 关联
    # 配置FastCGI,PHP 脚本请求全部转发到 FastCGI处理
    location ~ .*\.php$ {
        # 设置监听端口(多版本php用端口号区分)
        fastcgi_pass   127.0.0.1:9000;
        # 设置脚本文件请求的路径
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        # 引入fastcgi的配置文件
        include        fastcgi_params;
    }
}

保存之后,查看配置是否出错

nginx -t

重启nginx

service nginx restart

原文:https://www.cnblogs.com/stry/p/14949661.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐