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 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,則配置如下

# 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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM