作為一個開發人員,大家應該都用過nginx動態代理吧,話不多說,直接上步驟
注意,在root使用者下執行下面步驟:
步驟一:
yum install yum-utils -y
步驟二:
vim /etc/yum。repos。d/nginx。repo
步驟三:
[nginx-stable]name=nginx stable repobaseurl=http://nginx。org/packages/centos/$releasever/$basearch/gpgcheck=1enabled=1gpgkey=https://nginx。org/keys/nginx_signing。key[nginx-mainline]name=nginx mainline repobaseurl=http://nginx。org/packages/mainline/centos/$releasever/$basearch/gpgcheck=1enabled=0gpgkey=https://nginx。org/keys/nginx_signing。key
步驟四:
儲存步驟三的內容
步驟五:
yum-config-manager ——enable nginx-mainline
步驟六:
yum -y install nginx
至此,nginx安裝已經成功
注意點:
注意配置nginx。conf 將 user=root
常用命令:
systemctl start nginx 啟動nginx命令systemctl stop nginx 停止nginx命令systemctl restart nginx 重啟nginx命令
常用配置(80和443埠要在阿里雲裡面開啟)
靜態檔案:在/etc/nginx/conf。d下建一個web。conf
http方式請求————server { listen 80; server_name web。myweb。com; root /usr/local/dict; location / { index index。html index。htm; try_files $uri $uri/ /index。html; }}https方式請求————————-server { listen 443; server_name web。myweb。com; root /usr/local/dist; location / { index index。html index。htm; try_files $uri $uri/ /index。html; } ssl on; ssl_certificate /usr/cert/web。pem; ssl_certificate_key /usr/cert/web。key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1。1 TLSv1。2; ssl_prefer_server_ciphers on;}http自動重定向到https:————————server { listen 80; server_name web。myweb。com; return 301 https://web。myweb。com$request_uri;}
代理到後臺某一個埠:
listen 80; server_name h5。web。com; location / { proxy_pass http://127。0。0。1:5001/; proxy_redirect default; proxy_http_version 1。1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }}# 自動跳轉到手機頁面server { listen 80; server_name www。myweb。com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_pass http://pc。web。com; if ($http_user_agent ~ “(MIDP)|(WAP)|(UP。Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU。Browser)|(wxd。Mms)|(WxdB。Browser)|(CLDC)|(UP。Link)|(KM。Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1。0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)”) { proxy_pass http://h5。web。com; } }}
微信認證:wx。conf
server { listen 80; server_name wx。web。com; location ~ ^/[^/]+\。txt$ { return 200 “SCW6Ejcg96n6kqfL”; }}
完畢,至此nginx常用技能掌握完畢!
我是JAVA哥,願意與大家一些分享java