Nginx配置同時(shí)支持http和https的兩種方式
http:

https:
Nginx的ssl模塊安裝
進(jìn)入到目錄的sbin目錄下,輸入
#注意這里是大寫的V,小寫的只顯示版本號(hào) ./nginx -V
如果出現(xiàn) (configure arguments: --with-http_ssl_module), 則已安裝(下面的步驟可以跳過,直接進(jìn)行第五步)。
一般情況下都是不存在ssl模塊的,接下來進(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
接下來使用新的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í)候成功
#注意這里是大寫的V,小寫的只顯示版本號(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域名轉(zhuǎn)發(fā)使用場(chǎng)景代碼實(shí)例
這篇文章主要介紹了Nginx域名轉(zhuǎn)發(fā)使用場(chǎng)景代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
Windows上啟動(dòng)停止Nginx服務(wù)器的實(shí)用指南
在 Windows 上開發(fā) Django、Vue 或其他 Web 項(xiàng)目時(shí),Nginx 往往是我們最常用的反向代理服務(wù)器,下面小編就和大家介紹幾個(gè)在Windows系統(tǒng)上管理Nginx服務(wù)器的實(shí)用方案吧2026-02-02
windows系統(tǒng)安裝配置nginx環(huán)境
這篇文章介紹了windows系統(tǒng)安裝配置nginx環(huán)境的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06
詳解Nginx之Location配置(Location匹配順序)
這篇文章主要介紹了詳解Nginx之Location配置(Location匹配順序),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Ubuntu下Nginx1.28.0源碼編譯安裝與systemd管理方式解讀
這篇文章主要介紹了Ubuntu下Nginx1.28.0源碼編譯安裝與systemd管理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-05-05
nginx 部署啟動(dòng)jar包用到的一些命令和流程操作
這篇文章主要介紹了nginx 部署啟動(dòng)jar包用到的一些命令和流程操作,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-11-11

