45

Ubuntu Nginx Configuration Https

 5 years ago
source link: https://www.linuxprobe.com/nginx-configuration-https.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

环境说明:Ubuntu16.04.1 Nginx1.10.0 证书文件

修改配置文件:

sudo vim /etc/nginx/sites-available/default

server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;

##证书配置

ssl on;
ssl_certificate /file/name.crt; ##公钥目录
ssl_certificate_key /file/name.key; ##私钥目录
}

其他设置

Nginx PHP组件支持(php)

sudo vim /etc/nginx/sites-available/default

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_param;
}

80端口跳转443端口设置

server {
listen80 default;
server_name 你的域名;
rewrite ^(.*) https://$server_name$1 permanent;
}

隐藏Nginx版本号

sudo vim /etc/nginx/nginx.conf

server_tokens off; 

//去掉#注释即可,在http段

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK