nginx基本配置

nginx目录结构和命令

ls /usr/local/nginx/
html是测试页,sbin是主程序
ls /usr/local/nginx/sbin/
nginx只有一个程序文件
ls /usr/local/nginx/html/
50x.html index.html测试网页

Nginx :默认为启动nginx
-h查看帮助选项
-V查看版本和配置选项
-t测试nginx语法错误
-C filename指定配置文件(default: /etc/nginx/nginx.conf)
-S signal发送信号给master进程,signal : stop, quit, reopen, reload
示例: nginx -S stop
停止nginx
nginx -S reload
加载配置文件
-g directives在命令行中指明全局指令I

 

nginx配置文件

主配置文件结构:四部

main block :主配置段,即全局配置段,对http,mail都有效
event {

}

事件驱动相关的配置

http {
}

http/https协议相关配置段

mail {
}
mail协议相关配置段

stream {

}
stream服务器相关配置段

 

http {

...
..各server的公共配置
server {        每 个server用于定义一一个虚拟主机
...

}

server {
server_ name虚拟主机名
root 主目录
alias  路径别名,
location [OPERATOR] URL {     指定URL的特性

...

if CONDITION {

...

}
}
}
}

 

正常运行必备的配置:
帮助文档: http://nginx.org/en/docs/ngx_ core_ module.html
1、user
Syntax:user user[group];

Default:user nobody nobody;
Context: main
指定worker进程的运行身份,如组不指定,默认和用户名同名
2、pid /PATH/TO/PID_ FILE
指定存储nginx主进程PID的文件路径
3、include file | mask
指明包含进来的其它配置文件片断
4、load_ module file
模块加载配置文件: /usr/share/nginx/modules/* .conf
指明要装载的动态模块路径: /usr/lib64/nginx/modules

 

时哥笔记:

server {
#SSL 访问端口号为 443
listen 443;
#填写绑定证书的域名
server_name yunshimo.com;
#启用 SSL 功能
ssl on;
#证书文件名称
ssl_certificate cert/3813736yunshimo.com.pem;
#私钥文件名称
ssl_certificate_key cert/3813736yunshimo.com.key;
ssl_session_timeout 5m;
#请按照以下协议配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;

}

server {
listen 80;
server_name www.yunshimo.com yunshimo.com;
rewrite ^(.*)$ https://www.yunshimo.com redirect;
}

server {
listen 80;
server_name *.yunshimo.com;
rewrite ^(.*)$ https://$host$1 redirect;
}

server {
listen 80;
listen 443;
server_name www.yunshimo.com yunshimo.com;

location / {
proxy_pass http://localhost:8082/;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /rest/ {
proxy_pass http://localhost:8080/rest/;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

server {
listen 80;
listen 443;
server_name console.yunshimo.com;

location / {
proxy_pass http://localhost:8081;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /rest/ {
proxy_pass http://localhost:8080/rest/;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

点赞

发表评论

昵称和uid可以选填一个,填邮箱必填(留言回复后将会发邮件给你)
tips:输入uid可以快速获得你的昵称和头像

Title - Artist
0:00