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

https:
Nginx的ssl模塊安裝
進入到目錄的sbin目錄下,輸入
#注意這里是大寫的V,小寫的只顯示版本號 ./nginx -V
如果出現(xiàn) (configure arguments: --with-http_ssl_module), 則已安裝(下面的步驟可以跳過,直接進行第五步)。
一般情況下都是不存在ssl模塊的,接下來進入到你的解壓縮后的nginx目錄,注意這里不是nginx安裝目錄,是解壓縮后的目錄。
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
然后執(zhí)行
make #切記不要執(zhí)行make install,否則會重新安裝nginx
接下來使用新的nginx文件替換掉之前安裝目錄sbin下的nginx,注意這里的替換的時候可以先將之前的文件備份下,停掉nginx服務(wù)。
./nginx -s stop #停止nginx服務(wù) #替換之前的nginx cp /usr/nginx/objs/nginx /usr/local/nginx/sbin
成功之后,進入到nginx安裝目錄下,查看ssl時候成功
#注意這里是大寫的V,小寫的只顯示版本號 ./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配置同時支持http和https的兩種方式的文章就介紹到這了,更多相關(guān)Nginx配置同時支持http和https內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx配置編寫時支持邏輯運算與大小寫字母轉(zhuǎn)換的方法
這篇文章主要介紹了Nginx配置編寫時支持邏輯運算與大小寫字母轉(zhuǎn)換的方法,其中大小寫字母轉(zhuǎn)換是以lower upper case模塊來實現(xiàn),需要的朋友可以參考下2016-01-01
nginx添加http_ssl_module并且配置域名指定端口的操作方法
這篇文章主要介紹了nginx添加http_ssl_module并且配置域名指定端口的操作方法,文末附帶linux下防火墻和開放端口,需要的朋友可以參考下2023-11-11
Mac中使用Nginx實現(xiàn)80端口轉(zhuǎn)發(fā)8080端口
端口轉(zhuǎn)發(fā)(Port forwarding),有時被叫做隧道,是安全殼(SSH) 為網(wǎng)絡(luò)安全通信使用的一種方法。端口轉(zhuǎn)發(fā)是轉(zhuǎn)發(fā)一個網(wǎng)絡(luò)端口從一個網(wǎng)絡(luò)節(jié)點到另一個網(wǎng)絡(luò)節(jié)點的行為,其使一個外部用戶從外部經(jīng)過一個被激活的NAT路由器到達一個在私有內(nèi)部IP地址(局域網(wǎng)內(nèi)部)上的一個端口2017-09-09
Nginx啟動成功卻無法訪問網(wǎng)頁的問題分析和解決方案(完整的排除方案)
我是用的阿里云的服務(wù)器,所以我的問題就在于阿里云服務(wù)器必須單獨開端口,在找到這個問題之前,我已經(jīng)把所有能試的方法試過了一遍都沒有問題,在增加端口之后直接成功了,如果你也遇到了這樣的問題,就和我一起排除吧2023-12-12

