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時候成功文章來源:http://www.zghlxwxcb.cn/news/detail-537762.html
#注意這里是大寫的V,小寫的只顯示版本號
./nginx -V
#可以看到這里出現(xiàn)了configure arguments: --with-http_ssl_module 證明已經(jīng)安裝成功
nginx.conf
文章來源地址http://www.zghlxwxcb.cn/news/detail-537762.html
#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兩種方式訪問的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!