一.nginx實(shí)現(xiàn)訪問(wèn)
注意:服務(wù)器需要開(kāi)通80端口
server {
listen 80;
server_name 域名 例如xxx.com;
location / {
proxy_pass http://127.0.0.1:8080; #轉(zhuǎn)向的服務(wù)端口
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
二.一個(gè)域名下設(shè)置靜態(tài)服務(wù)配置
server {
listen 80;
server_name 域名 例如xxx.com;
location / {
proxy_pass http://127.0.0.1:8080; #轉(zhuǎn)向的服務(wù)端口
index index.html index.htm;
}
location /upload {
alias /www/wwwroot/upload/;
index index.html index.html;
client_max_body_size 50m;
}
location /upload {
root /www/wwwroot/;
index index.html index.html;
client_max_body_size 50m;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
(1)alias: alias指定的路徑是location的別名,不管location的值怎么寫(xiě),資源的 真實(shí)路徑都是 alias 指定的路徑
例如:同樣請(qǐng)求 http://xxx.com/upload/top.gif 時(shí),在服務(wù)器查找的資源路徑是: /www/wwwroot/upload/top.gif
(2)root:真實(shí)的路徑是root指定的值加上location指定的值 。
例如:同樣請(qǐng)求 http://xxx.com/upload/top.gif 時(shí),在服務(wù)器查找的資源路徑是: /www/wwwroot/upload/top.gif
其他區(qū)別:
1、 alias 只能作用在location中,而root可以存在server、http和location中。
2、 alias 后面必須要用 “/” 結(jié)束,否則會(huì)找不到文件,而 root 則對(duì) ”/” 可有可無(wú)。
三. 配置ssl證書(shū)實(shí)現(xiàn)https訪問(wèn)
注意:服務(wù)器需要開(kāi)通443端口文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-428207.html
阿里云服務(wù)器下載nginx安全證書(shū)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-428207.html
server
{
listen 443 ssl http2;
server_name 域名 例如xxx.com;
#SSL-START SSL相關(guān)配置,請(qǐng)勿刪除或修改下一行帶注釋的404規(guī)則
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
#HTTP_TO_HTTPS_END
ssl_certificate /cert/xxxxxx.pem; # 證書(shū)pem地址(我放在了和nginx.config同文件下的cert文件下了)
ssl_certificate_key /cert/xxxx.key; # 證書(shū)key地址
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
#SSL-END
location / {
root html;
index index.html index.htm;
proxy_pass http://127.0.0.1:8080; #轉(zhuǎn)向的地址
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
到了這里,關(guān)于Linux nginx實(shí)現(xiàn)訪問(wèn),配置ssl證書(shū)實(shí)現(xiàn)https訪問(wèn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!