Nginx 搭建域名訪問(wèn)環(huán)境的詳細(xì)過(guò)程
1.Nginx配置文件


server {
listen 80;
server_name www.gulimall.com;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
proxy_pass http://192.168.232.1:10001;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
讓所有的請(qǐng)求都轉(zhuǎn)到,商品服務(wù)

2.Nginx 搭建轉(zhuǎn)發(fā)網(wǎng)關(guān)進(jìn)行負(fù)載均衡
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream gulimall{
server 192.168.232.1:88;
}
include /etc/nginx/conf.d/*.conf;
}gulimall.conf
server {
listen 80;
server_name www.gulimall.com;
location / {
proxy_pass http://gulimall;
}
}
網(wǎng)關(guān) application.yml
- id: gulimall_host_route
uri: lb://gulimall-product
predicates:
- Host=www.gulimall.com有個(gè)坑
因?yàn)閚ginx代理給網(wǎng)關(guān)的時(shí)候會(huì) 丟掉請(qǐng)求頭里的host ,所以網(wǎng)關(guān)的匹配規(guī)則沒(méi)有匹配上導(dǎo)致404

需要配置Nginx
在gulimall.conf
location / {
proxy_set_header Host $host;
proxy_pass http://gulimall;
}

3.實(shí)現(xiàn)動(dòng)靜分離
location /static {
root /usr/share/nginx/html;
autoindex on; #開(kāi)啟文件目錄結(jié)構(gòu)在網(wǎng)頁(yè)顯示
}注意路徑會(huì)拼成, /usr/share/nginx/html/static

4.還有一個(gè)坑

這個(gè)匹配規(guī)則不要放前面,因?yàn)檫@些請(qǐng)求都是從上往下匹配的,匹配到了,就不往下匹配了,然而往nginx發(fā)送的域名都是 www.gulimall.com 所以,都會(huì)走第一個(gè)匹配,下面這些就匹配不上,就找不到那個(gè)接口就404了。
做好兩點(diǎn):
1.請(qǐng)求接口 http://域名/api/xxx
2.請(qǐng)求頁(yè)面 http://域名
轉(zhuǎn)發(fā)給網(wǎng)關(guān),通過(guò)網(wǎng)關(guān)路由到對(duì)應(yīng)的服務(wù) !
到此這篇關(guān)于Nginx 搭建域名訪問(wèn)環(huán)境的文章就介紹到這了,更多相關(guān)Nginx 域名訪問(wèn)環(huán)境內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
nginx隱藏server及版本號(hào)的實(shí)現(xiàn)
為了提高nginx服務(wù)器的安全性,降低被攻擊的風(fēng)險(xiǎn),需要隱藏nginx的server和版本號(hào),本文就來(lái)介紹一下nginx如何隱藏server及版本號(hào),具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08
利用Nginx的map指令實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)
每位網(wǎng)站運(yùn)營(yíng)人可能都會(huì)碰到一些情況,比如網(wǎng)站URL規(guī)則會(huì)進(jìn)行調(diào)整,需求的不斷變化也會(huì)導(dǎo)致一些舊的URL無(wú)法訪問(wèn),這個(gè)時(shí)候可以使用Nginx的 map指令匹配這些舊的URL,并跳轉(zhuǎn)到新的URL規(guī)則,而且這種方式是在Nginx層面進(jìn)行,不會(huì)對(duì)網(wǎng)站性能產(chǎn)生影響。下面來(lái)一起看看吧。2016-10-10
Nginx安裝nginx-rtmp-module模塊的實(shí)現(xiàn)
nginx-rtmp-module是一個(gè)用于Nginx的第三方模塊,它使Nginx能夠支持實(shí)時(shí)多媒體流的傳輸和處理,本文主要介紹了Nginx安裝nginx-rtmp-module模塊,具有一定的參考價(jià)值,感興趣的可以了解一下2025-02-02
Nginx中l(wèi)imit_req模塊和limit_conn模塊的使用
本文主要介紹了Nginx中l(wèi)imit_req模塊和limit_conn模塊的使用,通過(guò)limit_req和limit_conn模塊,可以有效實(shí)現(xiàn)精確的請(qǐng)求頻率和連接數(shù)控制,下面就來(lái)具體介紹一下2024-05-05
關(guān)于nginx+php5.3.8+eclipse3.7工作空間的配置方法
以前用eclipse3.6時(shí)設(shè)置php服務(wù)器時(shí)完全可以在base url欄填寫(xiě)自己工作空間的目錄,然后修改nginx.conf加一個(gè)alias就行了2011-11-11
nginx配置后訪問(wèn)出現(xiàn)白屏的問(wèn)題解決
本文主要介紹了nginx配置后訪問(wèn)出現(xiàn)白屏2024-06-06
詳解Nginx服務(wù)器中HTTP Headers相關(guān)的模塊配置使用
這篇文章主要介紹了詳解Nginx服務(wù)器中HTTP Headers相關(guān)的模塊配置使用,包括ngx_http_headers_module與它的增強(qiáng)版ngx_headers_more的配置使用講解,需要的朋友可以參考下2016-01-01

