目前想在nignx配置两个server
其中已经有一个配置了域名正在用。
另一个我可以把server name 配置成 xx.xxx.xx.xx/test
然后我通过 ip/test 访问么?
就是多个server 但只有一个域名 另外一个server 想通过ip地址+路径访问。
就像tomcat 里多个应用 直接ip/应用名 就能访问~~
|  |      1Livid MOD PRO /test 这个部分是通过 location 来配置的。 Nginx 配置的结构是 http -> server -> location | 
|  |      2ren2881971 OP @Livid 额。。 我是在location里配置的啊。  假如主机ip 是 123.4.5.6 同时我有一个域名www.xx.com并且有一个应用在这绑定这个域名运行中。 我可以把应用配置成 123.4.5.6/test 这种方式来访问么? 还是说必须配置成 www.xx.com/test 通过域名的方式来进行访问? | 
|  |      3ren2881971 OP @ren2881971 补充 把另一个应用配置成123.4.5.6/test  方式来访问 | 
|      4huson      2015-04-02 21:50:24 +08:00 在location /test  里面用 proxy_pass 反代到你的应用 | 
|  |      5ren2881971 OP @huson server { listen 80; server_name 123.56.118.252; index index.html index.htm index.php; root /alidata/www/weixin; location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } location /test{ proxy_pass http://123.56.118.252/; } 貌似location 配置的不对~~ 求教 | 
|  |      6zhujunsan      2015-04-02 22:15:21 +08:00 livid亲自来回复啦@@! location = /test{ proxy_pass http://123.56.118.252/; } location后面可以跟正则表达式,官方文档: http://nginx.org/en/docs/http/ngx_http_core_module.html#location | 
|  |      7ren2881971 OP @zhujunsan 额。。。。请求 *.php 还是会报403~~  location 还需要增加 php的匹配配置么。。 | 
|  |      8zhujunsan      2015-04-02 22:30:16 +08:00 @ren2881971 *.php被上面那条location吃掉了吧 XD | 
|  |      9ren2881971 OP | 
|      10myself      2015-04-02 22:48:20 +08:00 网站速度好快 | 
|  |      11zhujunsan      2015-04-02 22:48:41 +08:00 @ren2881971 2个不一样的二级域名。foo.xxx.com, bar.xxx.com这样分。不止两个server,几十个server也是正常,每个server写在一个配置文件里。 | 
|  |      12zhujunsan      2015-04-02 22:57:10 +08:00 | 
|  |      13ren2881971 OP @zhujunsan nginx 配置两个二级域名 那在万网哪里 我怎么配置。。只有一个ip啊。 | 
|  |      14zhujunsan      2015-04-02 23:03:32 +08:00 @ren2881971 DNS管理里面,设置两条A记录就好了。不过国内的话还是建议把DNS解析放到dnspod吧~免费稳定也很好用~ | 
|  |      15ren2881971 OP 难道nginx 就不能像tomcat 那样 自己定义url  匹配 应用么? 感觉反向代理是兜了个圈子啊。 | 
|  |      16ren2881971 OP @zhujunsan 额。。 我理解下哈 万网哪里两个二级域名都对应一个主机ip 然后在nginx里面  对不同的二级域名进行目录匹配是么? | 
|  |      17zhujunsan      2015-04-02 23:48:59 +08:00 via Android @ren2881971 嗯就是这样的 | 
|      18Busy      2015-04-02 23:49:30 +08:00 @ren2881971 你不觉得 nginx 跟 php-fpm  的通讯,就是一个反向代理的模型么?区别是有些监听端口,有些监听 socket,有些则监听 path | 
|      19kevin8096      2015-04-02 23:49:37 +08:00 location /test { index index.php; root /xxx if (!-f $request_filename) { rewrite ^(.*)$ /index.php last; break; } } location ~* \.php { root /xxx fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass 127.0.0.1:9999; include fastcgi.conf; } | 
|  |      20ren2881971 OP @Havee 太高深 听不懂 慢慢学吧。 反向代理在我这还是个新鲜名词~~~ | 
|  |      21ren2881971 OP @kevin8096 3q !!!! | 
|      22SharkIng      2015-04-03 06:09:27 +08:00 Livid居然换头像了....  location指定好路径,不指定主机名,就可以通过IP访问 但是需要确定下没有其他的Nginx配置,一般装Nginx的时候都会有一个default的配置指定了其他的路径的 | 
|  |      23ren2881971 OP @SharkIng 好的 目前已经解决3q! | 
|  |      24xiaobu      2015-04-03 09:43:29 +08:00 你访问IP,看访问的哪个目录,然后直接那个目录下面放test文件夹就行了 | 
|  |      25oamzn      2015-04-03 11:32:58 +08:00 网站访问速度好快,求服务器配置。 |