我想知道如果我将.htaccess文件内容移动到apache2的vhost文件中是否可以提高性能?
这是我的.htaccess的内容
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)
如果这样做是个好主意,我应该在vhost声明中放置哪些内容?
谢谢!
我有一个root服务器,上面运行着几个node.js项目.它们应该在自己的进程和目录中单独运行.考虑这个文件结构:
/home
+-- /node
+-- /someProject | www.some-project.com
| +-- index.js
| +-- anotherFile.img
| +-- ...
+-- /anotherProject | www.another-project.com
| +-- /stuff
| +-- index.js
| +-- ...
+-- /myWebsite | www.my-website.com
| +-- /static
| +-- index.js
| +-- ...
+-- ... | ...
Run Code Online (Sandbox Code Playgroud)
每个index.js应该开始与它的一个单独的处理cwd集合到它的父文件夹(someProject,anotherProject等).
想想ov vHosts.每个项目都会启动一个监听自己域名的Web服务器.而且存在问题.只有一个脚本可以启动,因为它们都尝试绑定到端口80.我深入研究了node.js API并寻找可能的解决方案:child_process.fork().
可悲的是,这不是很好.当我尝试将服务器实例发送到主进程(稍后发出请求)或者从主服务器request和response从主服务器到服务器的对象时,我得到错误.这是因为node.js在内部尝试将这些高级对象转换为JSON字符串,然后将其重新转换为其原始形式.这使得所有对象都失去了它们的引用和功能.
第二种方法 child.js
var http = require("http");
var server = http.createServer(function(req, res) {
// stuff...
});
server.listen(80); …Run Code Online (Sandbox Code Playgroud) 我感兴趣的是,如果我可以在域名上使用apache的vhosts: http://something.com/something或http:// {server-ip-address-here}/something?
我在Ubuntu服务器上使用Apache 2.2.20,这是我的家庭服务器,我在这里测试一些东西,我这里没有任何DNS服务器,我只有公共IP地址和从开放DNS服务附加到它的域名.
那么,我做了什么:
我把它放在那里(实际上它是从默认文件中修改而来的):
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName {mydomain-here}/demo/
DocumentRoot /vhosts/demo
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /vhosts/demo/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log …Run Code Online (Sandbox Code Playgroud)我的配置是:
Listen 443 http
NameVirtualHost *:80
NameVirtualHost *:443
ServerName *:80
<VirtualHost *:80>
[some non-ssl stuff]
ServerName account.example.com
</VirtualHost>
<VirtualHost *:443>
[some non-ssl stuff(directory, docroot)]
ServerName account.example.com
SSLEngine on
SSLCertificateFile /Users/myusername/certs/server.crt
SSLCertificateKeyFile /Users/myusername/certs/server.key
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
所以我无法访问我的网站的http版本,但ssl版本正常工作.我想使用vhosts,http(80)和https(443)通过mod_rewrite将http重写为https URL.
uname -a
Linux 3.4.62-53.42.amzn1.x86_64 GNU/Linux
httpd -v
Server version: Apache/2.2.25 (Unix)
Run Code Online (Sandbox Code Playgroud)
请帮助理解我做错了什么.
我正在尝试在我的测试环境中自动化一些新的站点部署.我的脚本自动生成apache vhost文件
/etc/apache2/sites-available/testsite.com
Run Code Online (Sandbox Code Playgroud)
然后a2ensite通过相同的脚本运行
a2ensite /etc/apache2/sites-available/testsite.com
Run Code Online (Sandbox Code Playgroud)
我明白了:
ERROR: No site found matching /etc/apache2/sites-available/testsite.com!
Run Code Online (Sandbox Code Playgroud)
该脚本以root身份运行.
我读过你必须从sites-available目录中获取a2ensite但如果这是通过脚本完成的,我怎么告诉a2ensite认为它在正确的目录中?
谢谢,
我计划尽快获得一个VPS并且有两个我想要托管的网站.我使用主机文件为我的开发环境设置了本地vhosts设置以正确移植它.
我的问题很简单:当设置两个单独的域指向一个VPS服务器时,Apache是否足够智能,就像在本地环境中一样,自动过滤任何对domain.com的请求到正确的VHOST,就像在本地一样?我想确定:)
谢谢!
我要问的例子:
说Domain1.com和Domain2.com都在我的VPS上.
当有人请求www.Domain1.com时,apache会看到并将其传递给domain1.com vhost文件.当有人请求www.Domain2.com时,apache会看到并将其传递给domain2.com vhost文件.
我在让PHP cURL库识别我在/etc/hosts文件中创建的别名时遇到了麻烦.
这就是我现在在/etc/hosts文件中的内容:
192.168.0.20 www.example.dev
Run Code Online (Sandbox Code Playgroud)
另一方面(192.168.0.20)Apache配置为在example.dev域上运行虚拟主机.如果我在浏览器上测试它,但是使用PHP cURL就不起作用了别名.
该hosts文件位于两台计算机上(192.168.0.10 <= PHP cli,192.168.0.20 <= Apache).
为了完整起见,这是我正在使用的PHP代码.
$this->url = 'http://www.example.dev/';
$this->ch = curl_init();
$header = array
(
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"Accept-Encoding: gzip,deflate,sdch",
"Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4",
"Cache-Control: max-age=0",
"Connection: keep-alive",
);
$sUserAgent = $this->tor ? UserAgents::getRandom() : UserAgents::CHROME16_LINUX;
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($this->ch, CURLOPT_USERAGENT, $sUserAgent);
curl_setopt($this->ch, CURLOPT_URL, $this->url);
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLINFO_HEADER_OUT, true);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, (bool) $waitResponse);
curl_setopt($this->ch, CURLOPT_VERBOSE, (bool) $this->verbose); …Run Code Online (Sandbox Code Playgroud) 我已经ProxyPass在虚拟主机中添加了,并在error.log文件中结束了以下错误.
proxy:没有协议处理程序对URL /有效.如果您使用的是DSO版本的mod_proxy,请确保使用LoadModule在配置中包含代理子模块.
在前端,当我请求特定页面时,我得到500.
我该如何解决这个错误?
系统:在使用Vagrant设置的Parallels VM上运行的Ubuntu 14.04 LAMP
我正在编写我的第一个非平凡的shell脚本,以便将新的Web项目添加到Mac笔记本电脑上的开发虚拟机中.
我已经复制了文件夹和文件,sed似乎很高兴自定义我的index.html和.conf vhost文件,但a2ensite似乎没有看到/ etc/apache2/sites-available /中的.conf文件
我测试它的存在,甚至打印调试列表:ls -al /etc/apache2/sites-available/ | grep $CONFFILE在尝试启用该站点之前.
我已经在这里和其他地方读过有关自Ubuntu 13(或14)以来的.conf扩展的重要性,这似乎是一个非常常见的问题.我的vhost文件具有.conf扩展名,所以这似乎是一个不同的问题.
谁能指出我正确的方向?我无法找到有关此特定问题的其他帖子.
我的感觉是我$CONFFILE在a2ensite命令中的变量扩展中出现错误,因为错误没有显示.conf扩展名,即使目录列表执行:
ERROR: Site /etc/apache2/sites-available/example-com-80 does not exist!
编辑:
按照下面每个Micheal的建议从命令行运行a2ensite后,它似乎解析得很好,但仍然没有显示扩展名:
$ sudo a2ensite example-com-80.conf
Enabling site example-com-80.
To activate the new configuration, you need to run:
service apache2 reload
Run Code Online (Sandbox Code Playgroud)
结束编辑
编辑:找到答案
在用更广泛的术语搜索之后a2ensite,我找到了一个两年前的问题,而不是Ubuntu 14.04 Vagrant等,@ raina77ow指出a2ensite只想要网站名称,而不是整个路径.更改sudo a2ensite /etc/apache2/sites-available/$CONFFILE为sudo a2ensite $CONFFILE
使脚本按预期工作.这也解释了为什么我之前从命令行运行的尝试 …
我已经安装了所需的工具,并按照几个教程试图让乘客做出回应.
我可以访问公用文件夹中的静态文件(public/500.html或422.hml).昨天我通过vhost进入,发现一些乘客错误.但是一段时间后托管重新启动了服务,从那以后我再也无法访问rails应用程序了.
这些是我用来配置服务器的一些链接.我也读到这可能是一个许可问题; 我已经检查过了,但我不确定它没问题.