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

配置如下:

#测试
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;
    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,则配置如下

# 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

猜你喜欢

转载自www.cnblogs.com/jackzhuo/p/12760497.html