Nginx配置多個(gè)訪問(wèn)路徑的實(shí)現(xiàn)
Nginx配置多個(gè)service 多個(gè)訪問(wèn)路徑
找到conf/nginx.conf修改配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
client_max_body_size 20M;
client_body_buffer_size 10M;
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
ssi on;
ssi_silent_errors on;
ssi_types text/html;
location / {
proxy_ignore_client_abort on;
root F:/xxxxxx/xxxxxx/xxxxxxxx;
index index.html;
}
location ^~ /api/ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080;
proxy_cookie_path / /;
proxy_pass_header Set-Cookie;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /file{
alias D:/imgs/;#指定圖片的路徑
autoindex on;
}
}
server {
listen 81;
server_name localhost;
ssi on;
ssi_silent_errors on;
ssi_types text/html;
location / {
proxy_ignore_client_abort on;
root F:/xxxxxx/xxxxxx/xxxxxxx;
index html/user/reg.html;
}
location ^~ /api/ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8081;
proxy_cookie_path / /;
proxy_pass_header Set-Cookie;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 82;
server_name localhost;
ssi on;
ssi_silent_errors on;
ssi_types text/html;
location / {
proxy_ignore_client_abort on;
root F:/xxxxxx/xxxxxxxx/xxxxxxx;
index index.html;
}
location ^~ /api/ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8082;
proxy_cookie_path / /;
proxy_pass_header Set-Cookie;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 83;
server_name localhost;
ssi on;
ssi_silent_errors on;
ssi_types text/html;
location / {
proxy_ignore_client_abort on;
root F:/xxxxx/xxxxxxx/xxxxxxxxx;
index index.html;
}
location ^~ /api/ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080;
proxy_cookie_path / /;
proxy_pass_header Set-Cookie;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 84;
server_name localhost;
ssi on;
ssi_silent_errors on;
ssi_types text/html;
location / {
proxy_ignore_client_abort on;
root F:/xxxxxxxn/xxxxxxxx/xxxxxxxxx;
index index.html;
}
location ^~ /api/ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080;
proxy_cookie_path / /;
proxy_pass_header Set-Cookie;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
參數(shù)說(shuō)明
- 修改 server 里面的 一些參數(shù)即可
- listen :端口
- server_name :訪問(wèn)地址
- root :項(xiàng)目路勁
- index :啟動(dòng)訪問(wèn)首頁(yè)
如果你想要多個(gè)路徑多配置 個(gè) server 即可
server {
listen 80;
server_name localhost;
ssi on;
ssi_silent_errors on;
ssi_types text/html;
location / {
proxy_ignore_client_abort on;
root F:/xxxxxx/xxxxxxx/xxxxxx;
index index.html;
}
location ^~ /api/ {
proxy_ignore_client_abort on;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:8080;
proxy_cookie_path / /;
proxy_pass_header Set-Cookie;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /file{
alias D:/imgs/;#指定圖片的路徑
autoindex on;
}
}
重新啟動(dòng)nginx、或者重新reload一下
start nginx 啟動(dòng) nginx -s reload 刷新 nginx -s stop
到此這篇關(guān)于Nginx配置多個(gè)訪問(wèn)路徑的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx配置多個(gè)訪問(wèn)路徑內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx服務(wù)器中配置非80端口的端口轉(zhuǎn)發(fā)方法詳解
這篇文章主要介紹了Nginx服務(wù)器中配置非80端口的端口轉(zhuǎn)發(fā)方法詳解,文中使用到了Nginx中的proxy_pass配置項(xiàng),需要的朋友可以參考下2016-04-04
nginx反向代理配置400,404,502等狀態(tài)的自定義頁(yè)面問(wèn)題
這篇文章主要介紹了nginx反向代理配置400,404,502等狀態(tài)的自定義頁(yè)面問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
nginx幾種網(wǎng)頁(yè)重定向(rewirte)的配置方法詳解
這篇文章主要詳細(xì)介紹了nginx幾種網(wǎng)頁(yè)重定向(rewirte)的配置方法,文中通過(guò)代碼示例和圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02
nginx如何根據(jù)報(bào)文里字段轉(zhuǎn)發(fā)至不同地址
要在 Nginx 中根據(jù) POST 請(qǐng)求的 JSON 負(fù)載中的 id 字段的值進(jìn)行轉(zhuǎn)發(fā),你可以使用 Nginx 的 ngx_http_lua_module 模塊,這個(gè)模塊允許你在 Nginx 配置中使用 Lua 腳本,本文介紹nginx如何根據(jù)報(bào)文里字段轉(zhuǎn)發(fā)至不同地址,感興趣的朋友一起看看吧2024-12-12
keepalived監(jiān)控nginx進(jìn)程的實(shí)現(xiàn)示例
本文主要介紹了keepalived監(jiān)控nginx進(jìn)程的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08
生產(chǎn)環(huán)境部署Nginx服務(wù)器雙機(jī)熱備部署keepalived的步驟(多種模式教程)
今天演示下生產(chǎn)環(huán)境keepalived的部署方式,安裝模式有很多,比如說(shuō)主備模型和雙主模型,主備分:搶占模式 和 非搶占模式,對(duì)Nginx keepalived 雙機(jī)熱備部署相關(guān)知識(shí)感興趣的朋友跟隨小編一起看看吧2024-07-07
Nginx服務(wù)器的SSL證書(shū)配置以及對(duì)SSL的反向代理配置
這篇文章主要介紹了Nginx服務(wù)器的SSL證書(shū)配置以及對(duì)SSL的反向代理配置方法,通常在開(kāi)啟全站HTTPS時(shí)會(huì)用到,需要的朋友可以參考下2016-01-01

