xuexb / learn-nginx Goto Github PK
View Code? Open in Web Editor NEWNginx 入门指南
Home Page: https://xuexb.github.io/learn-nginx/
License: MIT License
Nginx 入门指南
Home Page: https://xuexb.github.io/learn-nginx/
License: MIT License
proxy_pass.md
中 94 行
// 访问: /api/ 后端: /v1
// 访问: /api/xx 后端: /v1xx
// 访问: /api/xx?aa 后端: /v1xx
// 访问: /api-xx?aa 后端: /-xx?aa
location /api/ {
proxy_pass http://node:8080/v1;
}
其中的访问 /api-xx?aa
,应该是匹配失败的,不会被转发给后端。
您好,希望能更新一下关于upstream的配置,谢谢
目录下有两个文件
/www/sample1 // 没有后缀的PHP文件
/www/sample2.php // 有后缀的PHP文件
想要实现访问下面的链接,PHP能正常解析执行
http://localhost/sample1 // 解析执行/www/sample1
http://localhost/sample2 // 解析执行/www/sample2
http://localhost/sample2.php // 解析执行/www/sample2
同时浏览器访问 http://localhost 可以正常目录浏览
我折腾了几个小时nginx配置,前面两个sample1, sample2的需求可以了。
但是访问http://localhost ,nginx报404错误,没法目录浏览
当前配置:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 开启目录浏览
autoindex on;
server {
listen 80;
server_name t;
set $base /www;
root $base;
index index.html index.php;
location / {
try_files $uri $uri.html $uri/ $uri.php?$args /index.php?$query_string @extensionless-php;
}
location ~ (|\.php)$ {
try_files $uri $uri.php =404;
# fastcgi settings
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/www/:/usr/lib/php/:/tmp/";
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
}
文档我没有看懂,我本地 server
http://127.0.0.1:3000
, 请问如何正确的配置,才能访问 back-end serverhttp://10.1.5.203/api/test.json
?
#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 {
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 http://10.1.5.203;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# 202
location /api/{
proxy_pass http://127.0.0.1:3000;
}
location / {
add_header 'Access-Control-Allow-Origin' '*';
}
# 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# 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;
# }
#}
}
我的 .conf
哪里写错了呀?
Nginx 是要安装在服务器上,还是安装到本地的 PC 上?
proxy_pass
是指要代理的 backen
IP.
Nginx 安装到本地的 PC 上.
目前主机在内网环境没有域名,主机上使用端口运行服务,一个javaweb网站,
由于使用多个服务,希望能将端口反代成二级目录
使用proxy_pass 代理后出现web服务的静态资源无法访问,查看浏览器发现静态资源端口号没有反代
nginx 配置如下
location /wx/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Prefix /wx;
proxy_pass http://127.0.0.1:8080;
}
望解答!
nginx 从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.