Nginx配置同時(shí)支持http和https的兩種方式
http:
https:
Nginx的ssl模塊安裝
進(jìn)入到目錄的sbin目錄下,輸入
#注意這里是大寫(xiě)的V,小寫(xiě)的只顯示版本號(hào) ./nginx -V
如果出現(xiàn) (configure arguments: --with-http_ssl_module), 則已安裝(下面的步驟可以跳過(guò),直接進(jìn)行第五步)。
一般情況下都是不存在ssl模塊的,接下來(lái)進(jìn)入到你的解壓縮后的nginx目錄,注意這里不是nginx安裝目錄,是解壓縮后的目錄。
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
然后執(zhí)行
make #切記不要執(zhí)行make install,否則會(huì)重新安裝nginx
接下來(lái)使用新的nginx文件替換掉之前安裝目錄sbin下的nginx,注意這里的替換的時(shí)候可以先將之前的文件備份下,停掉nginx服務(wù)。
./nginx -s stop #停止nginx服務(wù) #替換之前的nginx cp /usr/nginx/objs/nginx /usr/local/nginx/sbin
成功之后,進(jìn)入到nginx安裝目錄下,查看ssl時(shí)候成功
#注意這里是大寫(xiě)的V,小寫(xiě)的只顯示版本號(hào) ./nginx -V #可以看到這里出現(xiàn)了configure arguments: --with-http_ssl_module 證明已經(jīng)安裝成功
nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name ip; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://ip:端口/; root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # server { listen 80; listen 443 ssl; server_name ip; location / { proxy_pass http://ip:端口/; } ssl_certificate /cert.pem; ssl_certificate_key /cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } } }
到此這篇關(guān)于Nginx配置同時(shí)支持http和https的兩種方式的文章就介紹到這了,更多相關(guān)Nginx配置同時(shí)支持http和https內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx配置編寫(xiě)時(shí)支持邏輯運(yùn)算與大小寫(xiě)字母轉(zhuǎn)換的方法
這篇文章主要介紹了Nginx配置編寫(xiě)時(shí)支持邏輯運(yùn)算與大小寫(xiě)字母轉(zhuǎn)換的方法,其中大小寫(xiě)字母轉(zhuǎn)換是以lower upper case模塊來(lái)實(shí)現(xiàn),需要的朋友可以參考下2016-01-01nginx添加http_ssl_module并且配置域名指定端口的操作方法
這篇文章主要介紹了nginx添加http_ssl_module并且配置域名指定端口的操作方法,文末附帶linux下防火墻和開(kāi)放端口,需要的朋友可以參考下2023-11-11Mac中使用Nginx實(shí)現(xiàn)80端口轉(zhuǎn)發(fā)8080端口
端口轉(zhuǎn)發(fā)(Port forwarding),有時(shí)被叫做隧道,是安全殼(SSH) 為網(wǎng)絡(luò)安全通信使用的一種方法。端口轉(zhuǎn)發(fā)是轉(zhuǎn)發(fā)一個(gè)網(wǎng)絡(luò)端口從一個(gè)網(wǎng)絡(luò)節(jié)點(diǎn)到另一個(gè)網(wǎng)絡(luò)節(jié)點(diǎn)的行為,其使一個(gè)外部用戶(hù)從外部經(jīng)過(guò)一個(gè)被激活的NAT路由器到達(dá)一個(gè)在私有內(nèi)部IP地址(局域網(wǎng)內(nèi)部)上的一個(gè)端口2017-09-09Nginx更換ssl證書(shū)不生效的問(wèn)題解決
本文主要介紹了Nginx配置中更換SSL證書(shū)后,新證書(shū)不生效的問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-12-12Nginx啟動(dòng)成功卻無(wú)法訪問(wèn)網(wǎng)頁(yè)的問(wèn)題分析和解決方案(完整的排除方案)
我是用的阿里云的服務(wù)器,所以我的問(wèn)題就在于阿里云服務(wù)器必須單獨(dú)開(kāi)端口,在找到這個(gè)問(wèn)題之前,我已經(jīng)把所有能試的方法試過(guò)了一遍都沒(méi)有問(wèn)題,在增加端口之后直接成功了,如果你也遇到了這樣的問(wèn)題,就和我一起排除吧2023-12-12Nginx解決前端訪問(wèn)資源跨域問(wèn)題的方法詳解
這篇文章主要給大家介紹了關(guān)于Nginx解決前端訪問(wèn)資源跨域問(wèn)題的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01Nginx下配置Https證書(shū)詳細(xì)過(guò)程
這篇文章主要介紹了Nginx下配置Https證書(shū)詳細(xì)過(guò)程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09