Last active
June 12, 2019 08:34
-
-
Save BoWang816/ec8f9510895a05571b03e5f206aa9387 to your computer and use it in GitHub Desktop.
[nginx安装与配置] #Nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nginx安装与配置 | |
安装nginx:sudo apt-get install nginx | |
启动: | |
sudo service nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade} | |
nginx配置: | |
* 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下 | |
* 程序文件在/usr/sbin/nginx | |
* 日志放在了/var/log/nginx中 | |
* 并已经在/etc/init.d/下创建了启动脚本nginx | |
* 默认的虚拟主机的目录设置在了/var/www/nginx-default (有的版本 默认的虚拟主机的目录设置在了/var/www, 请参考/etc/nginx/sites-available里的配置) | |
本地拷贝文件到服务器: | |
scp -r Nginx root@66.42.36.32:/root/cert | |
将Nginx文件夹拷贝到服务器/root/cert文件夹下 | |
配置SSL:vim nginx.conf | |
http{ | |
server { | |
listen 80; | |
listen [::]:80; | |
listen 443 ssl; | |
listen [::]:443 ssl; | |
server_name example.com; | |
# ssl on; 注释这个则http和https都支持 | |
ssl_certificate /cert/ssl.crt; | |
ssl_certificate_key /cert/ssl.key; | |
location / { | |
root /var/www/html/**; | |
index index.html index.htm index.jsp | |
} | |
} | |
} | |
重启并查看状态: | |
nginx -t && nginx -s reload | |
注意:项目中如果有用到http的外部链接,配置https之后,网站会提示不安全,但其实已经配置成功了,需要修改项目中的http外链。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment